package com.infodms.dms.actions.repairOrder;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.log4j.Logger;

import com.infodms.dms.bean.AclUserBean;
import com.infodms.dms.bean.TtAsRepairOrderExtBean;
import com.infodms.dms.bean.TtAsWrForeapprovalBean;
import com.infodms.dms.common.Constant;
import com.infodms.dms.common.ErrorCodeConstant;
import com.infodms.dms.common.Utility;
import com.infodms.dms.common.getCompanyId.GetOemcompanyId;
import com.infodms.dms.dao.claim.auditing.ClaimAuditingDao;
import com.infodms.dms.dao.claim.dealerClaimMng.ClaimBillMaintainDAO;
import com.infodms.dms.exception.BizException;
import com.infodms.dms.po.TcCodePO;
import com.infodms.dms.po.TmDealerPO;
import com.infodms.dms.po.TmVehiclePO;
import com.infodms.dms.po.TmVehiclePinRequestPO;
import com.infodms.dms.po.TtAsActivityPO;
import com.infodms.dms.po.TtAsRepairOrderBackupPO;
import com.infodms.dms.po.TtAsRepairOrderExtPO;
import com.infodms.dms.po.TtAsRepairOrderPO;
import com.infodms.dms.po.TtAsRoAddItemPO;
import com.infodms.dms.po.TtAsRoLabourPO;
import com.infodms.dms.po.TtAsRoRepairPartPO;
import com.infodms.dms.po.TtAsWrApplicationPO;
import com.infodms.dms.po.TtAsWrForeapprovalPO;
import com.infodms.dms.po.TtAsWrForeapprovalitemPO;
import com.infodms.dms.po.TtAsWrOtherfeePO;
import com.infodms.dms.po.TtAsWrOutrepairPO;
import com.infodms.dms.po.TtAsWrQamaintainPO;
import com.infodms.dms.util.CommonUtils;
import com.infodms.dms.util.sequenceUitl.SequenceManager;
import com.infoservice.dms.chana.vo.WarrantyPartVO;
import com.infoservice.mvc.context.ActionContext;
import com.infoservice.mvc.context.RequestWrapper;
import com.infoservice.po3.bean.PageResult;

public class RoMaintainMain {
	private Logger logger = Logger.getLogger(RoMaintainMain.class);
	private final ClaimBillMaintainDAO dao = ClaimBillMaintainDAO.getInstance();
	private final ClaimAuditingDao daom = ClaimAuditingDao.getInstance();
	private final String RO_URL = "/jsp/repairorder/roMaintain.jsp";// 主页面（查询）
	private final String RO_DEL_URL = "/jsp/repairorder/roDeleteMaintain.jsp";// 维修工单删除主页面(查询)Iverson add with 2010-11-12
	private final String RO_SHOP_URL = "/jsp/repairorder/roShopMaintain.jsp";// 主页面（查询）
	private final String RO_SHOP_DETAIL = "/jsp/repairorder/roShopDetail.jsp";// 经销商端主页面（查询）
	private final String RO_SHOP_DEALER = "/jsp/repairorder/roShopMainDealer.jsp";// 主页面（查询）
	private final String RO_SHOP_OEM = "/jsp/repairorder/roShopMainOEM.jsp";// 主页面（查询）
	private final String RO_ADD_URL = "/jsp/repairorder/roMaintainAdd.jsp";// 增加页面
	private final String RO_MODIFY_URL = "/jsp/repairorder/roMaintainModify.jsp";// 修改页面
	private final String RO_BALANCE_URL = "/jsp/repairorder/roBalanceMaintain.jsp"; //工单结算（查询）
	private final String RO_BALANCE_DETAIL = "/jsp/repairorder/roBalanceDetail.jsp"; //工单结算详细
	private final String RO_BALANCE_DETAIL2 = "/jsp/repairorder/roBalanceDetail2.jsp"; //工单结算详细
	private final String RO_DELETE_DETAIL = "/jsp/repairorder/roDeleteDetail.jsp"; //工单结算详细
	private final String RO_BALANCE_FOREAPPROVAL = "/jsp/repairorder/roMainforeapproval.jsp"; //预授权详细
	private final String CLAIM_BILL_MAINTAIN_DETAIL = "/jsp/claim/dealerClaimMng/3claimBillMaintainModify.jsp";//预授权申请2
	private final String RO_DELETE_DETAIL0 = "/jsp/repairorder/roDeleteDetail2.jsp"; //工单结算详细
	private final String VEHICLE_PIN_REPLY_QUERY = "/jsp/repairorder/vehiclePinReplyQuery.jsp"; //车辆PIN回复查询
	private final String VEHICLE_PIN_REPLY_DETAIL = "/jsp/repairorder/vehiclePinReplyDetail.jsp"; //车辆PIN明细查询
	private final String REPAIR_PART_DETAIL = "/jsp/repairorder/showRepairPartDetail.jsp"; //工单结算详细(配件)
	/**
	 * 
	 * @Title: roForward
	 * @Description: TODO(工单主页跳转)
	 * @param 设定文件
	 * @return void 返回类型
	 * @throws
	 */
	public void roForward() {
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean) act.getSession().get(
				Constant.LOGON_USER);
		try {
			act.setForword(RO_URL);
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "工单维护");
			logger.error(logonUser, e1);
			act.setException(e1);
		}
	}
	
	/**
	 * Iverson add with 2010-11-12
	 * @Title: roDeleteForward
	 * @Description: TODO(工单删除主页面跳转)
	 * @param 设定文件
	 * @return void 返回类型
	 * @throws
	 */
	public void roDeleteForward() {
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean) act.getSession().get(
				Constant.LOGON_USER);
		try {
			act.setForword(RO_DEL_URL);
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "工单删除");
			logger.error(logonUser, e1);
			act.setException(e1);
		}
	}
	
	/**
	 * 
	* @Title: roShopForward 
	* @Description: TODO(车厂端工单维护跳转) 
	* @param     设定文件 
	* @return void    返回类型 
	* @throws
	 */
	@SuppressWarnings("unchecked")
	public void roShopForward() {
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean) act.getSession().get(Constant.LOGON_USER);
		String dutyType = logonUser.getDutyType();
		@SuppressWarnings("unused")
		String orgId = "";
		String flag = "1";		
		try {
			if (dutyType.equals(Constant.DUTY_TYPE_LARGEREGION+"")) {
				flag = "2" ;  //如果是大区用户 YH.2010.12.15
			}						
			List provinces = this.getProvinceByUserId(logonUser.getUserId()); //YH 2010.12.16
			act.setOutData("flag",flag);
			act.setOutData("provinces",provinces);
			act.setForword(RO_SHOP_URL);
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "工单维护");
			logger.error(logonUser, e1);
			act.setException(e1);
		}
	}
	/**
	 * 
	* @Title: getProvinceByUserId
	* @Description: TODO(用户可查询的省市) 
	* @param     用户ID 
	* @return List    返回类型 
	* @throws
	 */
	@SuppressWarnings({ "unchecked", "unchecked" }) //YH 2010.12.16
	public List getProvinceByUserId(Long uid){
		
		StringBuffer sql= new StringBuffer();
		sql.append("select ur.user_id,ur.region_code,r.region_name\n" );
		sql.append(" from tc_user_region_relation ur ,tm_region r\n" );
		sql.append(" where ur.region_code = r.region_code and ur.user_id = '"+uid+"' \n");
		List list = dao.pageQuery(sql.toString(), null, dao.getFunName());
		return list;
	}
	
	/**
	 * 
	* @Title: roShopForward 
	* @Description: TODO(经销商端工单维护跳转) 
	* @param     设定文件 
	* @return void    返回类型 
	* @throws
	 */
	public void roViewForDealer() {
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean) act.getSession().get(
				Constant.LOGON_USER);
		try {
			act.setForword(RO_SHOP_DEALER);
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "工单维护");
			logger.error(logonUser, e1);
			act.setException(e1);
		}
	}
	/**
	 * 
	* @Title: roShopForward 
	* @Description: TODO(经销商端工单维护跳转) 
	* @param     设定文件 
	* @return void    返回类型 
	* @throws
	 */
	public void roViewForOem() {
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean) act.getSession().get(
				Constant.LOGON_USER);
		try {
			act.setForword(RO_SHOP_OEM);
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "工单维护");
			logger.error(logonUser, e1);
			act.setException(e1);
		}
	}
	/**
	 * 
	* @Title: roShopDetail 
	* @Description: TODO(车厂端工单详细页面) 
	* @param     设定文件 
	* @return void    返回类型 
	* @throws
	 */
	public void roShopDetail () {
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean) act.getSession().get(
				Constant.LOGON_USER);
		Long provinceId = null;
		String phone = "";
		try {
			RequestWrapper request = act.getRequest();
			TtAsActivityPO activity = new TtAsActivityPO();
			String id = request.getParamValue("ID");
			String roNo = request.getParamValue("roNo");
			String type = request.getParamValue("TYPE"); //1为明细，2为结算，3为取消结算
			
			List resList = daom.queryDealerById(Utility.getLong(logonUser
					.getDealerId()));
			if (resList != null && resList.size() > 0) {
				TmDealerPO dealerPO = (TmDealerPO) resList.get(0);
				phone = dealerPO.getPhone();
				provinceId = dealerPO.getProvinceId();
			}
			TtAsRepairOrderExtPO tawep = dao.queryRoById(id);
			List<TtAsRoRepairPartPO> partls = dao.queryRepairPart(null,id); // 取配件信息
			List<TtAsRoLabourPO> itemls = dao.queryRepairitem(null,id); // 取工时
			List<TtAsRoAddItemPO> otherls = dao.queryAddItem(null,id);// 取其他项目
			act.setOutData("application", tawep);

			act.setOutData("OTHERFEE", getOtherfeeStr());
			//act.setOutData("ACTIVITYCOMBO", getActivityStr());
			act.setOutData("ACTIVITY", activity);
			act.setOutData("ID", id);
			act.setOutData("itemLs", itemls);
			act.setOutData("partLs", partls);
			act.setOutData("otherLs", otherls);
			act.setOutData("phone", phone);
			act.setOutData("type", type);
			act.setForword(RO_SHOP_DETAIL);
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "工单维护");
			logger.error(logonUser, e1);
			act.setException(e1);
		}
		
	}
	/**
	 * 
	* @Title: shopApprove 
	* @Description: TODO(车厂端进行工单的授权审核通过和驳回) 
	* @param     设定文件 
	* @return void    返回类型 
	* @throws
	 */
	public void shopApprove() {

		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean) act.getSession().get(
				Constant.LOGON_USER);
		try {
			RequestWrapper request = act.getRequest();
			String id = request.getParamValue("ID"); 
			String type = request.getParamValue("TYPE"); //1为通过，2为拒绝
			String auditContent = request.getParamValue("AUDIT_CONTENT");
			TtAsRepairOrderPO tarop = new TtAsRepairOrderPO();
			tarop.setId(Utility.getLong(id));
			List ls  = dao.select(tarop);
			if (ls!=null) {
				if (ls.size()>0) {
					TtAsRepairOrderPO tarop0 = new TtAsRepairOrderPO();
					tarop0.setId(Utility.getLong(id));
					if ("1".equals(type)) {
						tarop0.setForlStatus(Constant.RO_FORE_02); //工单预授权通过
					}else if("2".equals(type)) {
						tarop0.setForlStatus(Constant.RO_FORE_03); //工单预授权拒绝
					}
					tarop0.setAuditContent(auditContent); //审核意见
					dao.update(tarop, tarop0);
					act.setOutData("success", true);
				}else {
					act.setOutData("success", false);
					act.setOutData("reason", true); //工单没有生成，不能授权
					
				}
			}else {
				
				act.setOutData("success", false);
				act.setOutData("reason", true); //工单没有生成，不能授权
			}
			act.setForword(RO_SHOP_URL);
			//tarop.setIs
			
		}catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "质量信息");
			act.setOutData("success", false);
			act.setOutData("reason", false);
			logger.error(logonUser, e1);
			act.setException(e1);
		}
	
	}
	/**
	 * 
	* @Title: roBalanceForward 
	* @Description: TODO(工单结算查询页面) 
	* @param     设定文件 
	* @return void    返回类型 
	* @throws
	 */
	public void roBalanceForward() {
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean) act.getSession().get(
				Constant.LOGON_USER);
		try {
			RequestWrapper request = act.getRequest();
			String type=request.getParamValue("type");
			if(type!=null&&Integer.valueOf(type)==4){act.setForword(RO_URL);}
			else{act.setForword(RO_BALANCE_URL);}
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "工单维护");
			logger.error(logonUser, e1);
			act.setException(e1);
		}
	}
	/**
	 * 
	* @Title: roBalanceDetail 
	* @Description: TODO(工单结算详细) 
	* @param     设定文件 
	* @return void    返回类型 
	* @throws
	 */
	public void roBalanceDetail() {
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean) act.getSession().get(
				Constant.LOGON_USER);
		Long provinceId = null;
		String phone = "";
		try {
			RequestWrapper request = act.getRequest();
			TtAsActivityPO activity = new TtAsActivityPO();
			String id = request.getParamValue("ID");
			String roNo = request.getParamValue("roNo");
			String type = request.getParamValue("type"); //1为明细，2为结算，3为取消结算
			if ("1".equals(type)) {
				act.setOutData("showBalButton",false);
				act.setOutData("showCanButton",false);
			}else if ("2".equals(type)) {
				//判断登陆系统
//				List<Map<String,Object>> ListCode =   dao.queryTcCode();
//			    Integer code = Integer.valueOf(ListCode.get(0).get("CODE_ID").toString());
//			    if(code==Constant.chana_wc){
				
					//检查工单配件是不是配件大类
					/*List<Map<String,String>> partCode = dao.getRepairOrderPartCheck(id); 
					String checkFlag = CommonUtils.checkNull(request.getParamValue("checkFlag"));
					if(!"".equals(checkFlag)){
						boolean flag = false;
						String flagStr = "0";
						for(int j=0;j<partCode.size();j++){
							if(partCode.get(j).get("PART_TYPE_ID")==null){
								flag = true;
								flagStr = "1";
								break;
							}
						}
						if(flag){
							act.setOutData("flag", flag);
							act.setOutData("flagStr", flagStr);
							act.setOutData("partCode", partCode);
							act.setOutData("id", id);
							act.setOutData("roNo", roNo);
							act.setOutData("type", type);
							act.setForword(REPAIR_PART_DETAIL);
							
							
							
							return;
						}
						else{
							
							
						}
					}
					
					//在工单添加配件大类标志(如果没有标志或标为不是配件大类)
					
					TtAsRepairOrderPO repair = new TtAsRepairOrderPO();
					repair.setId(Long.valueOf(id));
					TtAsRepairOrderPO selRepair = (TtAsRepairOrderPO)dao.select(repair).get(0);
					String partFlag = CommonUtils.checkNull(selRepair.getPartFlag());
					if("".equals(partFlag)||"0".equals(partFlag)){
						TtAsRepairOrderPO repairValue = new TtAsRepairOrderPO();
						repairValue.setUpdateBy(logonUser.getUserId());
						repairValue.setUpdateDate(new Date());
						repairValue.setPartFlag(1);
						dao.update(repair, repairValue);
					}*/
					//在工单添加配件大类标志(如果没有标志或标为不是配件大类)
//				}
				act.setOutData("showBalButton",true);
				act.setOutData("showCanButton",false);
			}else if ("3".equals(type)) {
				TtAsWrApplicationPO tarop = new TtAsWrApplicationPO();
				tarop.setRoNo(roNo);
				act.setOutData("showBalButton",false);
				List<TtAsWrApplicationPO> ls = dao.select(tarop);
				if (ls!=null) {
					if (ls.size()>0) {
						act.setOutData("showCanButton",false);
					}else {
						act.setOutData("showCanButton",true);
					}
				}else {
					act.setOutData("showCanButton",true);
				}
			}
			List resList = daom.queryDealerById(Utility.getLong(logonUser
					.getDealerId()));
			if (resList != null && resList.size() > 0) {
				TmDealerPO dealerPO = (TmDealerPO) resList.get(0);
				if(dealerPO.getPhone()!=null){
					phone = dealerPO.getPhone();	
				}
				
				
				provinceId = dealerPO.getProvinceId();
			}
			TtAsRepairOrderExtPO tawep = dao.queryRoById(id);
			List<TtAsRoRepairPartPO> partls = dao.queryRepairPart(null,id); // 取配件信息
			List<TtAsRoLabourPO> itemls = dao.queryRepairitem(null,id); // 取工时
			List<TtAsRoAddItemPO> otherls = dao.queryAddItem(null,id);// 取其他项目
			act.setOutData("application", tawep);

			int freeTimes = 0 ; //结算页面的一个标识     0:允许   1：不允许  -->针对保养次数<=当前系统保养次数的情况
			//如果是保养类型，则执行此次判断
			if(Constant.REPAIR_TYPE_04.equals(tawep.getRepairTypeCode())){
				act.setOutData("flag_if", true);
				String vin = tawep.getVin() ;
				List<TmVehiclePO> car = dao.getCar(vin);
				if(car!=null){
					if(car.size()>0){
						try{
							freeTimes = car.get(0).getFreeTimes() ;
						}catch(Exception e){
							logger.info("此车的保养次数字段未初始化，默认为0");
						}
					}
				}
			}
			//查询tc_code 8008 区分轿微车
			TcCodePO code = new TcCodePO() ;
			code.setType("8008") ;
			List list = dao.select(code) ;
			if(list.size()>0)
				code = (TcCodePO)list.get(0);
			act.setOutData("code", code) ;
			act.setOutData("freeTimes",freeTimes);
			act.setOutData("OTHERFEE", getOtherfeeStr());
			//act.setOutData("ACTIVITYCOMBO", getActivityStr());
			act.setOutData("ACTIVITY", activity);
			act.setOutData("ID", id);
			act.setOutData("itemLs", itemls);
			act.setOutData("partLs", partls);
			act.setOutData("otherLs", otherls);
			act.setOutData("phone", phone);
			act.setOutData("type", type);
			String action=CommonUtils.checkNull(request.getParamValue("action"));
			if("000".equals(type)){
				act.setForword(RO_DELETE_DETAIL0);
			}
			else if(action.equals("detail"))
				act.setForword(RO_BALANCE_DETAIL2);
			else
				act.setForword(RO_BALANCE_DETAIL);
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "工单维护");
			logger.error(logonUser, e1);
			act.setException(e1);
		}
	}
	
	
	
	public void roBalanceDetail2() {
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean) act.getSession().get(
				Constant.LOGON_USER);
		Long provinceId = null;
		String phone = "";
		try {
			RequestWrapper request = act.getRequest();
			TtAsActivityPO activity = new TtAsActivityPO();
			String id = request.getParamValue("ID");
			String roNo = request.getParamValue("roNo");
			String type = request.getParamValue("type"); //1为明细，2为结算，3为取消结算
			if ("1".equals(type)) {
				act.setOutData("showBalButton",false);
				act.setOutData("showCanButton",false);
			}else if ("2".equals(type)) {
				//判断登陆系统
				List<Map<String,Object>> ListCode =   dao.queryTcCode();
			    Integer code = Integer.valueOf(ListCode.get(0).get("CODE_ID").toString());
			    if(code==Constant.chana_wc){
				
					//检查工单配件是不是配件大类
					List<Map<String,String>> partCode = dao.getRepairOrderPartCheck(id); 
					String checkFlag = CommonUtils.checkNull(request.getParamValue("checkFlag"));
					if(!"".equals(checkFlag)){
						boolean flag = false;
						String flagStr = "0";
						for(int j=0;j<partCode.size();j++){
							if(partCode.get(j).get("PART_TYPE_ID")==null){
								flag = true;
								flagStr = "1";
								break;
							}
						}
						if(flag){
							act.setOutData("flag", flag);
							act.setOutData("flagStr", flagStr);
							act.setOutData("partCode", partCode);
							act.setOutData("id", id);
							act.setOutData("roNo", roNo);
							act.setOutData("type", type);
							act.setForword(REPAIR_PART_DETAIL);
							
							
							
							return;
						}
						else{
							
							
						}
					}
					
				}
				act.setOutData("showBalButton",true);
				act.setOutData("showCanButton",false);
			}else if ("3".equals(type)) {
				TtAsWrApplicationPO tarop = new TtAsWrApplicationPO();
				tarop.setRoNo(roNo);
				act.setOutData("showBalButton",false);
				List<TtAsWrApplicationPO> ls = dao.select(tarop);
				if (ls!=null) {
					if (ls.size()>0) {
						act.setOutData("showCanButton",false);
					}else {
						act.setOutData("showCanButton",true);
					}
				}else {
					act.setOutData("showCanButton",true);
				}
			}
			List resList = daom.queryDealerById(Utility.getLong(logonUser
					.getDealerId()));
			if (resList != null && resList.size() > 0) {
				TmDealerPO dealerPO = (TmDealerPO) resList.get(0);
				if(dealerPO.getPhone()!=null){
					phone = dealerPO.getPhone();	
				}
				
				
				provinceId = dealerPO.getProvinceId();
			}
			TtAsRepairOrderExtPO tawep = dao.queryRoById(id);
			List<TtAsRoRepairPartPO> partls = dao.queryRepairPart(null,id); // 取配件信息
			List<TtAsRoLabourPO> itemls = dao.queryRepairitem(null,id); // 取工时
			List<TtAsRoAddItemPO> otherls = dao.queryAddItem(null,id);// 取其他项目
			act.setOutData("application", tawep);

			int freeTimes = 0 ; //结算页面的一个标识     0:允许   1：不允许  -->针对保养次数<=当前系统保养次数的情况
			//如果是保养类型，则执行此次判断
			if(Constant.REPAIR_TYPE_04.equals(tawep.getRepairTypeCode())){
				act.setOutData("flag_if", true);
				String vin = tawep.getVin() ;
				List<TmVehiclePO> car = dao.getCar(vin);
				if(car!=null){
					if(car.size()>0){
						try{
							freeTimes = car.get(0).getFreeTimes() ;
						}catch(Exception e){
							logger.info("此车的保养次数字段未初始化，默认为0");
						}
					}
				}
			}
			
			act.setOutData("freeTimes",freeTimes);
			act.setOutData("OTHERFEE", getOtherfeeStr());
			//act.setOutData("ACTIVITYCOMBO", getActivityStr());
			act.setOutData("ACTIVITY", activity);
			act.setOutData("ID", id);
			act.setOutData("itemLs", itemls);
			act.setOutData("partLs", partls);
			act.setOutData("otherLs", otherls);
			act.setOutData("phone", phone);
			act.setOutData("type", type);
			String action=CommonUtils.checkNull(request.getParamValue("action"));
			//查询tc_code 8008 区分轿微车
			TcCodePO code = new TcCodePO() ;
			code.setType("8008") ;
			List list = dao.select(code) ;
			if(list.size()>0)
				code = (TcCodePO)list.get(0);
			act.setOutData("code", code) ;
			if("000".equals(type)){
				act.setForword(RO_DELETE_DETAIL0);
			}
			else if(action.equals("detail"))
				act.setForword(RO_BALANCE_DETAIL2);
			else
				act.setForword(RO_BALANCE_DETAIL);
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "工单维护");
			logger.error(logonUser, e1);
			act.setException(e1);
		}
	}
	
	
	/**
	 * Iverson add with 2010-11-12
	 * @Title: roDeleteDetail 
	 * @Description: TODO(工单删除详细页面) 
	 * @param     设定文件 
	 * @return void    返回类型 
	 * @throws
	 */
	public void roDeleteDetail() {
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean) act.getSession().get(
				Constant.LOGON_USER);
		Long provinceId = null;
		String phone = "";
		try {
			RequestWrapper request = act.getRequest();
			TtAsActivityPO activity = new TtAsActivityPO();
			String id = request.getParamValue("ID");
			String roNo = request.getParamValue("roNo");
			String type = request.getParamValue("type"); //1为明细，2为结算，3为取消结算
			if ("1".equals(type)) {
				act.setOutData("showBalButton",false);
				act.setOutData("showCanButton",false);
			}else if ("2".equals(type)) {
				act.setOutData("showBalButton",true);
				act.setOutData("showCanButton",false);
			}else if ("3".equals(type)) {
				TtAsWrApplicationPO tarop = new TtAsWrApplicationPO();
				tarop.setRoNo(roNo);
				act.setOutData("showBalButton",false);
				List<TtAsWrApplicationPO> ls = dao.select(tarop);
				if (ls!=null) {
					if (ls.size()>0) {
						act.setOutData("showCanButton",false);
					}else {
						act.setOutData("showCanButton",true);
					}
				}else {
					act.setOutData("showCanButton",true);
				}
			}
			List resList = daom.queryDealerById(Utility.getLong(logonUser
					.getDealerId()));
			if (resList != null && resList.size() > 0) {
				TmDealerPO dealerPO = (TmDealerPO) resList.get(0);
				if(dealerPO.getPhone()!=null){
					phone = dealerPO.getPhone();	
				}
				
				
				provinceId = dealerPO.getProvinceId();
			}
			TtAsRepairOrderExtPO tawep = dao.queryRoById(id);
			List<TtAsRoRepairPartPO> partls = dao.queryRepairPart(null,id); // 取配件信息
			List<TtAsRoLabourPO> itemls = dao.queryRepairitem(null,id); // 取工时
			List<TtAsRoAddItemPO> otherls = dao.queryAddItem(null,id);// 取其他项目
			/**************Iverson add 2010-11-14 此功能判断如果工单生成了索赔单就必须先删除索赔单再删除工单*******************/
			TtAsRepairOrderPO po = new TtAsRepairOrderPO();
			po.setId(Long.parseLong(id));
			List rono = dao.getRoNoById(po);
			TtAsRepairOrderPO roNoValue = (TtAsRepairOrderPO)rono.get(0);
			long listRono = dao.queryTtAsWrApplication(roNoValue.getRoNo());
			/**************Iverson add 2010-11-14 此功能判断如果工单生成了索赔单就必须先删除索赔单再删除工单 end***************/
			act.setOutData("application", tawep);
			int freeTimes = 0 ; //结算页面的一个标识     0:允许   1：不允许  -->针对保养次数<=当前系统保养次数的情况
			//如果是保养类型，则执行此次判断
			if(Constant.REPAIR_TYPE_04.equals(tawep.getRepairTypeCode())){
				act.setOutData("flag_if", true);
				String vin = tawep.getVin() ;
				List<TmVehiclePO> car = dao.getCar(vin);
				if(car!=null){
					if(car.size()>0){
						try{
							freeTimes = car.get(0).getFreeTimes() ;
						}catch(Exception e){
							logger.info("此车的保养次数字段未初始化，默认为0");
						}
					}
				}
			}
			//查询tc_code 8008 区分轿微车
			TcCodePO code = new TcCodePO() ;
			code.setType("8008") ;
			List list = dao.select(code) ;
			if(list.size()>0)
				code = (TcCodePO)list.get(0);
			act.setOutData("code", code) ;
			act.setOutData("freeTimes",freeTimes);
			act.setOutData("OTHERFEE", getOtherfeeStr());
			act.setOutData("ACTIVITY", activity);
			act.setOutData("ID", id);
			act.setOutData("itemLs", itemls);
			act.setOutData("partLs", partls);
			act.setOutData("otherLs", otherls);
			act.setOutData("phone", phone);
			act.setOutData("type", type);
			/******************Iverson add 2010-11-14 此功能判断如果工单生成了索赔单就必须先删除索赔单再删除工单*****************************/
			act.setOutData("listRono", listRono);
			/******************Iverson add 2010-11-14 此功能判断如果工单生成了索赔单就必须先删除索赔单再删除工单 end****************************/
			act.setForword(RO_DELETE_DETAIL);
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "工单维护");
			logger.error(logonUser, e1);
			act.setException(e1);
		}
	}
	
	/**
	 * Iverson add with 2010-12-07
	 * @Title: roDeleteDetail 
	 * @Description: TODO(查询根据工单ID看看这个工单是否有特殊费用) 
	 * @param     设定文件 
	 * @return void    返回类型 
	 * @throws
	 */
	public void roDeleteDetail1() {
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean) act.getSession().get(Constant.LOGON_USER);
		try {
			RequestWrapper request = act.getRequest();
			String id = request.getParamValue("id");
			int count = daom.queryDealerById1(id);
			if(count>0){
				act.setOutData("ok", "ok");
			}else{
				act.setOutData("id", id);
			}
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "工单维护");
			logger.error(logonUser, e1);
			act.setException(e1);
		}
	}
	
	/**
	 * 
	* @Title: roBalanceDetail 
	* @Description: TODO(预授权申请单明细与结算明细一样) 
	* @param     设定文件 
	* @return void    返回类型 
	* @throws
	 */
	public void roBalanceDetail1() {
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean) act.getSession().get(
				Constant.LOGON_USER);
		Long provinceId = null;
		String phone = "";
		try {
			RequestWrapper request = act.getRequest();
			TtAsActivityPO activity = new TtAsActivityPO();
			String roNo = request.getParamValue("roNo");
			String fId = request.getParamValue("FID");//获取预授权ID 
			String type = request.getParamValue("type"); //1为明细，2为审核
			if ("1".equals(type)) {
				act.setOutData("showBalButton",false);
				act.setOutData("showCanButton",false);
			}else if ("2".equals(type)) {
				act.setOutData("showBalButton",true);
				act.setOutData("showCanButton",true);
			}
			List resList = daom.queryDealerById(Utility.getLong(logonUser
					.getDealerId()));
			if (resList != null && resList.size() > 0) {
				TmDealerPO dealerPO = (TmDealerPO) resList.get(0);
				phone = dealerPO.getPhone();
				provinceId = dealerPO.getProvinceId();
			}
			List<Map<String, Object>> list = dao.getID(roNo);
			String id =list.get(0).get("ID").toString(); 
			TtAsRepairOrderExtPO tawep = dao.queryRoById(id);
			List<TtAsRoRepairPartPO> partls = dao.queryRepairPart(null,id); // 取配件信息
			List<TtAsRoLabourPO> itemls = dao.queryRepairitem(null,id); // 取工时
			List<TtAsRoAddItemPO> otherls = dao.queryAddItem(null,id);// 取其他项目
			List<Map<String, Object>> listOpinion = dao.getOpinion(fId);
			String dealerId = logonUser.getDealerId();
			if(dealerId!=null){
				act.setOutData("flag", 1);
			}else{
				act.setOutData("flag", 0);
			}
			act.setOutData("list3", listOpinion.get(0));
			act.setOutData("application", tawep);
			act.setOutData("OTHERFEE", getOtherfeeStr());
			//act.setOutData("ACTIVITYCOMBO", getActivityStr());
			act.setOutData("ACTIVITY", activity);
			act.setOutData("ID", id);
			act.setOutData("itemLs", itemls);
			act.setOutData("partLs", partls);
			act.setOutData("otherLs", otherls);
			act.setOutData("phone", phone);
			act.setOutData("type", type);
			act.setOutData("fId",fId);
			act.setForword(RO_BALANCE_FOREAPPROVAL);
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "工单维护");
			logger.error(logonUser, e1);
			act.setException(e1);
		}
	}
	/**
	 * 
	* @Title: roBalance 
	* @Description: TODO(工单结算) 
	* @param     设定文件 
	* @return void    返回类型 
	* @throws
	 */
	public void roBalance() {
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean) act.getSession().get(
				Constant.LOGON_USER);
		try {
			RequestWrapper request = act.getRequest();
			String id = request.getParamValue("ID");
			TtAsRepairOrderPO tarop = new TtAsRepairOrderPO();
			tarop.setId(Utility.getLong(id));
			TtAsRepairOrderPO taropUp = new TtAsRepairOrderPO();
			taropUp.setId(Utility.getLong(id));
			taropUp.setRoStatus(Constant.RO_STATUS_02); //以结算
			taropUp.setUpdateDate(new Date());//结算时间
			
			List<Map<String,String>> partCode = dao.getRepairOrderPartCheck(id); 
			boolean flag = false;
			for(int j=0;j<partCode.size();j++){
				if(partCode.get(j).get("PART_TYPE_ID")==null){
					flag = true;
					break;
				}
			}
			if(!flag){
				taropUp.setPartFlag(1);   //属于配件大类
			}else{
				taropUp.setPartFlag(0);   //不属于配件大类
			}
			
			
			dao.update(tarop, taropUp);
			act.setForword(RO_BALANCE_URL);
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "工单维护");
			logger.error(logonUser, e1);
			act.setException(e1);
		}
	}
	/**
	 * 
	* @Title: roBalanceCancle 
	* @Description: TODO(取消结算) 
	* @param     设定文件 
	* @return void    返回类型 
	* @throws
	 */
	public void roBalanceCancle () {
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean) act.getSession().get(
				Constant.LOGON_USER);
		try {
			RequestWrapper request = act.getRequest();
			String id = request.getParamValue("ID");
			TtAsRepairOrderPO tarop = new TtAsRepairOrderPO();
			tarop.setId(Utility.getLong(id));
			TtAsRepairOrderPO taropUp = new TtAsRepairOrderPO();
			taropUp.setId(Utility.getLong(id));
			taropUp.setRoStatus(Constant.RO_STATUS_01); //以结算
			dao.update(tarop, taropUp);
			act.setForword(RO_BALANCE_URL);
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "工单维护");
			logger.error(logonUser, e1);
			act.setException(e1);
		}
		
	}
	/**
	 * 
	* @Title: roAddForward 
	* @Description: TODO(工单新增跳转) 
	* @param     设定文件 
	* @return void    返回类型 
	* @throws
	 */
	public void roAddForward() {
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean) act.getSession().get(
				Constant.LOGON_USER);
		String dealerId = logonUser.getDealerId();
		String phone;
		try {
			TmDealerPO tdp = new TmDealerPO();
			TtAsActivityPO activity = new TtAsActivityPO();
			tdp.setDealerId(Utility.getLong(dealerId));
			List<TmDealerPO> lsd = dao.select(tdp);
			if (lsd != null) {
				if (lsd.size() > 0) {
					tdp = lsd.get(0);
				}
			}
			if(tdp.getPhone()==null||tdp.getPhone().equals("")){
				phone = "";
					
				}
				else{
					phone=tdp.getPhone();
				}
			SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
			Date date = new Date();
			String now = sf.format(date);
			RequestWrapper request = act.getRequest();
			//查询tc_code 8008 区分轿微车
			TcCodePO code = new TcCodePO() ;
			code.setType("8008") ;
			List list = dao.select(code) ;
			if(list.size()>0)
				code = (TcCodePO)list.get(0);
			act.setOutData("code", code) ;
			act.setOutData("roNo", "");
			act.setOutData("OTHERFEE", getOtherfeeStr());
			//act.setOutData("ACTIVITYCOMBO", getActivityStr());
			act.setOutData("dealerName", tdp.getDealerName());
			act.setOutData("dealerCode", tdp.getDealerCode());
			act.setOutData("phone", phone);
			act.setOutData("now", now);
			act.setForword(RO_ADD_URL);
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,ErrorCodeConstant.QUERY_FAILURE_CODE, "索赔单维护");
			logger.error(logonUser, e1);
			act.setException(e1);
		}
	}
	
	public void roModifyForward1(String id,String type) {
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean) act.getSession().get(
				Constant.LOGON_USER);
		Long companyId = GetOemcompanyId.getOemCompanyId(logonUser); // 公司ID
		Long provinceId = null;
		String phone = "";

		try {
			RequestWrapper request = act.getRequest();
			TtAsActivityPO activity = new TtAsActivityPO();
			List resList = daom.queryDealerById(Utility.getLong(logonUser
					.getDealerId()));
			if (resList != null && resList.size() > 0) {
				TmDealerPO dealerPO = (TmDealerPO) resList.get(0);
				if(dealerPO.getPhone()!=null){
					phone = dealerPO.getPhone();
				}
				provinceId = dealerPO.getProvinceId();
			}
			TtAsRepairOrderExtPO tawep = dao.queryRoById(id);
			String roNo = tawep.getRoNo();
			List<TtAsRoRepairPartPO> partls = dao.queryRepairPart(null,id); // 取配件信息
			List<TtAsRoLabourPO> itemls = dao.queryRepairitem(null,id); // 取工时
			List<TtAsRoAddItemPO> otherls = dao.queryAddItem(null,id);// 取其他项目
			String remark2 = "";
			if(tawep.getRemark2()!=null){
				remark2=tawep.getRemark2();
				
			}
			//查询tc_code 8008 区分轿微车
			TcCodePO code = new TcCodePO() ;
			code.setType("8008") ;
			List list = dao.select(code) ;
			if(list.size()>0)
				code = (TcCodePO)list.get(0);
			act.setOutData("code", code) ;
			act.setOutData("application", tawep);
			act.setOutData("remark2", remark2);
			if(tawep.getRepairTypeCode().equals(Constant.REPAIR_TYPE_02) ||tawep.getRepairTypeCode().equals(Constant.REPAIR_TYPE_04)){
			act.setOutData("flag", true);
			}
			else{
				act.setOutData("flag", false);
			}
			act.setOutData("type", type);
			act.setOutData("OTHERFEE", getOtherfeeStr());
			//act.setOutData("ACTIVITYCOMBO", getActivityStr());
			act.setOutData("ACTIVITY", activity);
			act.setOutData("ID", id);
			act.setOutData("itemLs", itemls);
			act.setOutData("partLs", partls);
			act.setOutData("otherLs", otherls);
			act.setOutData("phone", phone);
			TtAsWrApplicationPO ta1 = new TtAsWrApplicationPO();
			ta1.setRoNo(roNo);
			List lsapp = dao.select(ta1);
			if (lsapp!=null) {
				//工单在索赔单中存在不可修改，跳转到明细页面
				if (lsapp.size()>0) {
					act.setOutData("exist", true);
					act.setForword(RO_BALANCE_DETAIL);
				}else {
					act.setOutData("exist", false);
					act.setForword(RO_MODIFY_URL);
				}
			}else {
				act.setOutData("exist", false);
				act.setForword(RO_MODIFY_URL);
			}
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "索赔单维护");
			logger.error(logonUser, e1);
			act.setException(e1);
		}
	}
	
	/**
	 * 
	* @Title: roModifyForward 
	* @Description: TODO(工单修改跳转) 
	* @param     设定文件 
	* @return void    返回类型 
	* @throws
	 */
	public void roModifyForward() {
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean) act.getSession().get(
				Constant.LOGON_USER);
		Long companyId = GetOemcompanyId.getOemCompanyId(logonUser); // 公司ID
		Long provinceId = null;
		String phone = "";
		String remark2="";
		try {
			RequestWrapper request = act.getRequest();
			TtAsActivityPO activity = new TtAsActivityPO();
			String id = request.getParamValue("ID");
			String type=request.getParamValue("type");//等于4的话表示工单已结算返回时返回 到工单首页
			List resList = daom.queryDealerById(Utility.getLong(logonUser
					.getDealerId()));
			//String phone="";
			if (resList != null && resList.size() > 0) {
				TmDealerPO dealerPO = (TmDealerPO) resList.get(0);
				if(dealerPO.getPhone()!=null){
					phone = dealerPO.getPhone();	
				}
				provinceId = dealerPO.getProvinceId();
			}
			TtAsRepairOrderExtBean tawep = dao.queryRoById(id);
			String roNo = tawep.getRoNo();
			List<TtAsRoRepairPartPO> partls = dao.queryRepairPart(null,id); // 取配件信息
			List<TtAsRoLabourPO> itemls = dao.queryRepairitem(null,id); // 取工时
			List<TtAsRoAddItemPO> otherls = dao.queryAddItem(null,id);// 取其他项目
			act.setOutData("application", tawep);
			if(tawep.getRepairTypeCode().equals(Constant.REPAIR_TYPE_02) ||tawep.getRepairTypeCode().equals(Constant.REPAIR_TYPE_04)){
			act.setOutData("flag", true);
			}
			else{
				act.setOutData("flag", false);
			}
			if(tawep.getRemark2()!=null){
				remark2 = tawep.getRemark2();
			}
			act.setOutData("type", type);
			act.setOutData("OTHERFEE", getOtherfeeStr());
			//act.setOutData("ACTIVITYCOMBO", getActivityStr());
			act.setOutData("ACTIVITY", activity);
			act.setOutData("ID", id);
			act.setOutData("itemLs", itemls);
			act.setOutData("partLs", partls);
			act.setOutData("otherLs", otherls);
			act.setOutData("phone", phone);
			act.setOutData("remark2", remark2);
			TtAsWrApplicationPO ta1 = new TtAsWrApplicationPO();
			ta1.setRoNo(roNo);
			List lsapp = dao.select(ta1);
			//查询tc_code 8008 区分轿微车
			TcCodePO code = new TcCodePO() ;
			code.setType("8008") ;
			List list = dao.select(code) ;
			if(list.size()>0)
				code = (TcCodePO)list.get(0);
			act.setOutData("code", code) ;
			if (lsapp!=null) {
				//工单在索赔单中存在不可修改，跳转到明细页面
				if (lsapp.size()>0) {
					act.setOutData("exist", true);
					act.setForword(RO_BALANCE_DETAIL);
				}else {
					act.setOutData("exist", false);
					act.setForword(RO_MODIFY_URL);
				}
			}else {
				act.setOutData("exist", false);
				act.setForword(RO_MODIFY_URL);
			}
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "索赔单维护");
			logger.error(logonUser, e1);
			act.setException(e1);
		}
	}
	/**
	 * 
	* @Title: roModifyForward 
	* @Description: TODO(工单修改跳转) 
	* @param     设定文件 
	* @return void    返回类型 
	* @throws
	 */
	public void roModifyForward3() {
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean) act.getSession().get(
				Constant.LOGON_USER);
		Long companyId = GetOemcompanyId.getOemCompanyId(logonUser); // 公司ID
		Long provinceId = null;
		String phone = "";
		String remark2="";
		try {
			RequestWrapper request = act.getRequest();
			TtAsActivityPO activity = new TtAsActivityPO();
			String id = request.getParamValue("ID");
			String type=request.getParamValue("type");//等于4的话表示工单已结算返回时返回 到工单首页
			List resList = daom.queryDealerById(Utility.getLong(logonUser
					.getDealerId()));
			//String phone="";
			if (resList != null && resList.size() > 0) {
				TmDealerPO dealerPO = (TmDealerPO) resList.get(0);
				if(dealerPO.getPhone()!=null){
					phone = dealerPO.getPhone();	
				}
				provinceId = dealerPO.getProvinceId();
			}
			TtAsRepairOrderExtBean tawep = dao.queryRoById(id);
			String roNo = tawep.getRoNo();
			List<TtAsRoRepairPartPO> partls = dao.queryRepairPart(null,id); // 取配件信息
			List<TtAsRoLabourPO> itemls = dao.queryRepairitem(null,id); // 取工时
			List<TtAsRoAddItemPO> otherls = dao.queryAddItem(null,id);// 取其他项目
			act.setOutData("application", tawep);
			if(tawep.getRepairTypeCode().equals(Constant.REPAIR_TYPE_02) ||tawep.getRepairTypeCode().equals(Constant.REPAIR_TYPE_04)){
			act.setOutData("flag", true);
			}
			else{
				act.setOutData("flag", false);
			}
			if(tawep.getRemark2()!=null){
				remark2 = tawep.getRemark2();
			}
			act.setOutData("type", type);
			act.setOutData("OTHERFEE", getOtherfeeStr());
			//act.setOutData("ACTIVITYCOMBO", getActivityStr());
			act.setOutData("ACTIVITY", activity);
			act.setOutData("ID", id);
			act.setOutData("itemLs", itemls);
			act.setOutData("partLs", partls);
			act.setOutData("otherLs", otherls);
			act.setOutData("phone", phone);
			act.setOutData("remark2", remark2);
			TtAsWrApplicationPO ta1 = new TtAsWrApplicationPO();
			ta1.setRoNo(roNo);
			List lsapp = dao.select(ta1);
			act.setForword(CLAIM_BILL_MAINTAIN_DETAIL);
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "索赔单维护");
			logger.error(logonUser, e1);
			act.setException(e1);
		}
	}
	/**
	 * 
	 * @Title: getOtherfeeStr
	 * @Description: TODO(取得其他费用下拉框)
	 * @param
	 * @param type
	 * @param
	 * @return 设定文件
	 * @return String 返回类型
	 * @throws
	 */
	public String getOtherfeeStr() {
		ActionContext ctx = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean) ctx.getSession().get(
				Constant.LOGON_USER);

		Long companyId = GetOemcompanyId.getOemCompanyId(logonUser); // 公司ID
		List<TtAsWrOtherfeePO> seriesList = dao.queryOtherFee(companyId);
		String retStr = "";
		retStr += "<option value=\'\'>-请选择-</option>";
		for (int i = 0; i < seriesList.size(); i++) {
			TtAsWrOtherfeePO bean = new TtAsWrOtherfeePO();
			bean = (TtAsWrOtherfeePO) seriesList.get(i);
			retStr += "<option value=\'" + bean.getFeeCode() + "\'"
					+ "title=\'" + bean.getFeeName() + "\'>"
					+ bean.getFeeCode() + "-" + bean.getFeeName() + "</option>";
		}
		return retStr;
	}
	
	public void accredit() throws Exception{
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean) act.getSession().get(
				Constant.LOGON_USER);
		float labourHoursMain = 0f; // 基本工时数
		float reinForceHoursMain = 0f; // 附加工时数
		double stdHourAmount = 0; // 基本工时金额
		double reinHourAmount = 0; // 附加工时金额
		int partsCount = 0; // 总配件数
		double labourAmountMain = 0; // 总工时金额
		double partsAmountMain = 0; // 配件金额
		double netItemAmount = 0; // 其他项目金额
		double repairTotal = 0; // 索赔申请金额
		RequestWrapper request = act.getRequest();
		String remark = request.getParamValue("remark_ysq");//预授权申请内容
		String yieldly = request.getParamValue("YIELDLY"); // 产地
		String brandCode = request.getParamValue("BRAND_CODE0"); // 品牌
		String modelCode = request.getParamValue("MODEL_CODE0"); // 车型
		String seriesCode = request.getParamValue("SERIES_CODE0");// 车系
		String engineNo = request.getParamValue("ENGINE_NO");
		String gearboxNo = request.getParamValue("GEARBOX_NO0"); // 变速箱
		String rearaxleNo = request.getParamValue("REARAXLE_NO0"); // 后桥
		String transferNo = request.getParamValue("TRANSFER_NO0"); // 分动器
		String dealerCode = request.getParamValue("DEALER_CODE");
		String roNo = request.getParamValue("RO_NO"); // 工单号
		String roStartdate = request.getParamValue("RO_STARTDATE");// 工单开始时间
		String serveAdvisor = request.getParamValue("SERVE_ADVISOR");// 接待员
		String vin = request.getParamValue("VIN_FOR");// VIN
		String freeTimes = request.getParamValue("freeTimes");//获取保养次数
		String claimType = request.getParamValue("repareType"); // 索赔类型
		
		String inMileage = request.getParamValue("IN_MILEAGE");
		
		String delivererPhone = request.getParamValue("DELIVERER_PHONE");
		String dealerId = request.getParamValue("dealerId");
		String delivererAdress = request.getParamValue("DELIVERER_ADRESS");
		String outLicenseno = request.getParamValue("OUT_LICENSENO");
		TtAsWrForeapprovalPO po = new TtAsWrForeapprovalPO();//预授权申请单主表
		Long id = Utility.getLong(SequenceManager.getSequence(""));
		String code = SequenceManager.getSequence2("YSQ");
		po.setId(id);//主键ID 
		po.setRemark(remark);//预授权信息
		po.setFoNo(code);
		po.setRoNo(roNo);
		po.setStartTime(Utility.getDate(roStartdate, 1));
		po.setVin(vin);
		po.setDealerId(Long.valueOf(dealerId));
		po.setLicenseNo(outLicenseno);
		po.setEngineNo(engineNo);
		po.setBrandCode(brandCode);
		po.setSeriesCode(seriesCode);
		po.setModelCode(modelCode);
		po.setGearboxNo(gearboxNo);
		po.setRearaxleNo(rearaxleNo);
		po.setTransferNo(transferNo);
		po.setYieldly(yieldly);
		po.setInMileage(Double.valueOf(inMileage));
		po.setDeliverer(delivererAdress);//送修人
		po.setDelivererPhone(delivererPhone);//送修电话
		po.setApprovalType(Integer.valueOf(claimType));//申请类型
		//po.setApprovalDate(approvalDate);//申请时间
		po.setDestClerk(serveAdvisor);//接待员
		po.setReportStatus(Constant.RO_FORE_01);//状态
		po.setCreateDate(new Date());
		po.setCreateBy(logonUser.getUserId());
		if(!freeTimes.equals("")||freeTimes!=null){
		po.setFreeTime(Integer.valueOf(freeTimes));
		}
		dao.insertTtAsWrForeapprovalPO(po);
		
		/*****
		 * 插入明细
		 */
		// 主工时
		
		String[] wrLabourCodes = request.getParamValues("WR_LABOURCODE"); // 获取工时代码
		String[] labourHours = request.getParamValues("LABOUR_HOURS"); // 获取工时数
		String[] labourAmounts = request.getParamValues("LABOUR_AMOUNT"); // 获取工时金额
		String[] partCodes = request.getParamValues("PART_CODE"); // 上件代码
		String[] prices = request.getParamValues("PRICE"); // 单价
		String[] amounts = request.getParamValues("QUANTITY"); // 数量
		String[] itemCodes = request.getParamValues("ITEM_CODE"); // 其他项目代码
		String[] itemAmounts = request.getParamValues("ITEM_AMOUNT");// 其他项目金额
		
		// 主工时插入
		if (wrLabourCodes != null) {
			for (int i = 0; i < wrLabourCodes.length; i++) {
				/* if (i == 0) { */
				// 主工时数量和金额
				labourHoursMain = Utility.getFloat(labourHours[i]);
				stdHourAmount = Utility.getDouble(labourAmounts[i]);
				// 累加总工时金额
				TtAsWrForeapprovalitemPO itemPo = new TtAsWrForeapprovalitemPO();
				itemPo.setFid(id);//预授权主键ID
				itemPo.setId(Utility.getLong(SequenceManager.getSequence("")));
				itemPo.setRoNo(roNo);
				itemPo.setItemType(Constant.PRE_AUTH_ITEM_01);
				itemPo.setItemQuantity(Double.valueOf(labourHours[i]));
				itemPo.setItemAmount(stdHourAmount);
				itemPo.setDealerCode(dealerCode);
				itemPo.setCreateDate(new Date());
				itemPo.setCreateBy(logonUser.getUserId());
				dao.insertTtAsWrForeapprovalitemPO(itemPo);
			}
		}
		if (partCodes != null) {
			for (int i = 0; i < partCodes.length; i++) {
				TtAsWrForeapprovalitemPO itemPo = new TtAsWrForeapprovalitemPO();
				itemPo.setFid(id);//预授权主键ID
				itemPo.setId(Utility.getLong(SequenceManager.getSequence("")));
				itemPo.setRoNo(roNo);
				itemPo.setItemType(Constant.PRE_AUTH_ITEM_02);
				itemPo.setItemQuantity(Double.valueOf(amounts[i]));
				itemPo.setItemAmount(Double.valueOf(amounts[i])*Double.valueOf(prices[i]));
				itemPo.setDealerCode(dealerCode);
				itemPo.setCreateDate(new Date());
				itemPo.setCreateBy(logonUser.getUserId());
				dao.insertTtAsWrForeapprovalitemPO(itemPo);
			}
		}
		// 其他项目插入
		if (itemCodes != null) {
			for (int i = 0; i < itemCodes.length; i++) {
				TtAsRoRepairPartPO tawp = new TtAsRoRepairPartPO();
				TtAsWrForeapprovalitemPO itemPo = new TtAsWrForeapprovalitemPO();
				itemPo.setFid(id);//预授权主键ID
				itemPo.setId(Utility.getLong(SequenceManager.getSequence("")));
				itemPo.setRoNo(roNo);
				itemPo.setItemType(Constant.PRE_AUTH_ITEM_03);
				itemPo.setItemAmount(Double.valueOf(itemAmounts[i]));
				itemPo.setDealerCode(dealerCode);
				itemPo.setCreateDate(new Date());
				itemPo.setCreateBy(logonUser.getUserId());
				dao.insertTtAsWrForeapprovalitemPO(itemPo);
			}
		}
		//将工单的状态更新
		dao.backOrderRono(roNo);
		//roUpdate();
		act.setOutData("success", true);
		
		
	}

	/**
	 * 
	 * @Title: roInsert
	 * @Description: TODO(新增工单)
	 * @param 设定文件
	 * @return void 返回类型
	 * @throws
	 */
	public void roInsert() throws BizException{
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean) act.getSession().get(
				Constant.LOGON_USER);
		Long companyId = GetOemcompanyId.getOemCompanyId(logonUser);
		String dealerId = logonUser.getDealerId();
		StringBuffer con = new StringBuffer();
		Date date = new Date();
		try {

			RequestWrapper request = act.getRequest();
			Integer curPage = request.getParamValue("curPage") != null ? Integer
					.parseInt(request.getParamValue("curPage"))
					: 1; // 处理当前页
			Integer pageSize = 10;
			float labourHoursMain = 0f; // 基本工时数
			float reinForceHoursMain = 0f; // 附加工时数
			double stdHourAmount = 0; // 基本工时金额
			double reinHourAmount = 0; // 附加工时金额
			int partsCount = 0; // 总配件数
			double labourAmountMain = 0; // 总工时金额
			double partsAmountMain = 0; // 配件金额
			double netItemAmount = 0; // 其他项目金额
			double repairTotal = 0; // 索赔申请金额
			String TROUBLE_DESC = request.getParamValue("TROUBLE_DESC");//故障描述
			String TROUBLE_REASON = request.getParamValue("TROUBLE_REASON");//故障原因
			String REPAIR_METHOD = request.getParamValue("REPAIR_METHOD");//故障措施
			String APP_REMARK = request.getParamValue("APP_REMARK");//申请备注
			String roId = request.getParamValue("roId"); // 从工单带过来的roId:为提交时更新工单附属表使用
			String ownerName = request.getParamValue("CTM_NAME_1");//车主姓名
			String yieldly = request.getParamValue("YIELDLY"); // 产地
			String licenseNo = request.getParamValue("LICENSE_NO"); // 车牌号
			String brandCode = request.getParamValue("BRAND_CODE0"); // 品牌
			String brandName = request.getParamValue("BRAND_NAME0");
			String modelCode = request.getParamValue("MODEL_CODE0"); // 车型
			String modelName = request.getParamValue("MODEL_NAME0");
			String seriesCode = request.getParamValue("SERIES_CODE0");// 车系
			String seriesName = request.getParamValue("SERIES_NAME0");
			String engineNo = request.getParamValue("ENGINE_NO");
			String gearboxNo = request.getParamValue("GEARBOX_NO0"); // 变速箱
			String rearaxleNo = request.getParamValue("REARAXLE_NO0"); // 后桥
			String transferNo = request.getParamValue("TRANSFER_NO0"); // 分动器
			//String APPROVAL_YN = request.getParamValue("APPROVAL_YN");//预授权标示
			String dealerCode = request.getParamValue("DEALER_CODE");
			String roNo = request.getParamValue("RO_NO"); // 工单号
			String lineNo = request.getParamValue("LINE_NO");// 行号
			String roStartdate = request.getParamValue("RO_STARTDATE");// 工单开始时间
			String roEnddate = request.getParamValue("RO_ENDDATE");// 工单结束时间
			String guaranteeDate = request.getParamValue("GUARANTEE_DATE");// 购车日期
			String serveAdvisor = request.getParamValue("SERVE_ADVISOR");// 接待员
			String vin = request.getParamValue("VIN");// VIN
			String remark = request.getParamValue("APP_REMARK");// 申请备注
			String claimType = request.getParamValue("CLAIM_TYPE"); // 索赔类型
			String troubleDesc = request.getParamValue("TROUBLE_DESC");
			String troubleReason = request.getParamValue("TROUBLE_REASON");
			String repairMethod = request.getParamValue("REPAIR_METHOD");
			String inMileage = request.getParamValue("IN_MILEAGE");
			String deliverer = request.getParamValue("DELIVERER");
			String delivererPhone = request.getParamValue("DELIVERER_PHONE");
			String delivererMobile = request.getParamValue("DELIVERER_MOBILE");
			String delivererAdress = request.getParamValue("DELIVERER_ADRESS");
			String repairType = request.getParamValue("REPAIR_TYPE");
			String startTime = request.getParamValue("START_DATE");
			String endTime = request.getParamValue("END_DATE");
			//zhumingwei 2011-03-09
			String hh = request.getParamValue("hh");
			String mm = request.getParamValue("mm");
			String hhmm = startTime+" "+hh+":"+mm;
			
			String hh1 = request.getParamValue("hh1");
			String mm1 = request.getParamValue("mm1");
			String hhmm1 = endTime+" "+hh1+":"+mm1;
			//zhumingwei 2011-03-09
			
			String outPerson = request.getParamValue("OUT_PERSON");
			String outSite = request.getParamValue("OUT_SITE");
			String outLicenseno = request.getParamValue("OUT_LICENSENO");
			String fromAdress = request.getParamValue("FROM_ADRESS");
			String endAdress = request.getParamValue("END_ADRESS");
			String outMileage = request.getParamValue("OUT_MILEAGE");
			String activityCode = request.getParamValue("ACTIVITYCOMBO");
			String campaignCode = request.getParamValue("CAMPAIGN_CODE"); // 服务活动代码
			String campaignFee = request.getParamValue("CAMPAIGN_FEE"); // 服务活动费用
			String remark2 = request.getParamValue("remark_ysq");//获取预授权申请内容
			String isFixing = request.getParamValue("IS_FIX"); // 服务活动是否固定费用1为固定费用

			String freeMAmount = request.getParamValue("FREE_M_AMOUNT"); // 免费保养次数
			String freeMPrice = request.getParamValue("FREE_M_PRICE"); // 免费保养费用
			String freeTimes = request.getParamValue("freeTimes"); //免费保养次数

			// 主工时
			String[] items = request.getParamValues("MAIN_ITEM"); // 工时选择的CHECKBOX
			String[] wrLabourCodes = request.getParamValues("WR_LABOURCODE"); // 获取工时代码
			String[] wrLabournames = request.getParamValues("WR_LABOURNAME"); // 获取工时名称
			String[] labourHours = request.getParamValues("LABOUR_HOURS"); // 获取工时数
			String[] labourPrices = request.getParamValues("LABOUR_PRICE"); // 获取工时单价
			String[] labourAmounts = request.getParamValues("LABOUR_AMOUNT"); // 获取工时金额
			String[] damageType = request.getParamValues("DAMAGE_TYPE"); // 质损类型
			String[] damageArea = request.getParamValues("DAMAGE_AREA"); // 质损区域
			String[] damageDegree = request.getParamValues("DAMAGE_DEGREE"); // 质损程度
			String[] troubleCode = request.getParamValues("TROUBLE_CODE"); // 故障代码
			String[] itemIsFore = request.getParamValues("ITEM_IS_FORE"); //是否授权
			String[] itemPayType = request.getParamValues("PAY_TYPE_ITEM");//付费方式
			// 附加工时
			String[] bMlCode = request.getParamValues("B_ML_CODE");
			String[] wrLabourCodes0 = request.getParamValues("WR_LABOURCODE0"); // 获取工时代码
			String[] wrLabournames0 = request.getParamValues("WR_LABOURNAME0"); // 获取工时名称
			String[] labourHours0 = request.getParamValues("LABOUR_HOURS0"); // 获取工时数
			String[] labourPrices0 = request.getParamValues("LABOUR_PRICE0"); // 获取工时单价
			String[] labourAmounts0 = request.getParamValues("LABOUR_AMOUNT0"); // 获取工时金额

			String[] parts = request.getParamValues("PART");// 配件选择的CHECKBOX
			String[] partCodes = request.getParamValues("PART_CODE"); // 上件代码
			String[] partNames = request.getParamValues("PART_NAME"); // 上件名称
			String[] downPartCodes = request.getParamValues("DOWN_PART_CODE"); // 下件代码
			String[] downPartNames = request.getParamValues("DOWN_PART_NAME"); // 下件名称
			String[] quantitys = request.getParamValues("QUANTITY"); // 上件数量
			String[] prices = request.getParamValues("PRICE"); // 单价
			String[] amounts = request.getParamValues("AMOUNT"); // 数量
			String[] supplierCodes = request.getParamValues("PRODUCER_CODE");// 生产商代码
			String[] supplierNames = request.getParamValues("PRODUCER_NAME"); // 生产商名称
			String[] downSupplierCodes = request.getParamValues("PRODUCER_CODE1");// 生产商代码
			String[] downSupplierNames = request.getParamValues("PRODUCER_NAME1"); // 生产商名称
			String[] remarks = request.getParamValues("REMARK"); // 故障描述
			String[] appTime = request.getParamValues("appTime"); // 索赔工时
			String[] bMpCode = request.getParamValues("B_MP_CODE");// 所属主配件
			String[] partIsFore = request.getParamValues("PART_IS_FORE");//是否授权
			String[] partPayType = request.getParamValues("PAY_TYPE_PART"); //配件付费方式
			String[] isGua = request.getParamValues("IS_GUA"); //是否在三包范围内
			
			String[] itemCodes = request.getParamValues("ITEM_CODE"); // 其他项目代码
			String[] itemNames = request.getParamValues("ITEM_NAME"); // 其他项目名称
			String[] itemAmounts = request.getParamValues("ITEM_AMOUNT");// 其他项目金额
			String[] itemRemarks = request.getParamValues("ITEM_REMARK");// 备注
			String[] otherIsFore = request.getParamValues("OTHER_IS_FORE");//是否授权
			String[] otherPayType = request.getParamValues("PAY_TYPE_OTHER"); //其他付费方式
			int checkday = 999999;
			int accredit =0;//判断是否需要授权
			int is_gua = 0;
			//判断VIN 和工单号是否为空
			if (Constant.REPAIR_TYPE_01.equals(repairType)) {//一般维修
				startTime = null;
				endTime = null;
				outPerson = null;
				outSite = null;
				outLicenseno = null;
				fromAdress = null;
				endAdress = null;
				outMileage = null;
				campaignCode = null;
				freeTimes = null;
				String code = sequenceRoNo();
				roNo = Utility.GetBillNo("",logonUser.getDealerCode(),"RO");
			}else if (Constant.REPAIR_TYPE_02.equals(repairType)) {//外出维修
				campaignCode = null;
				freeTimes = null;
				accredit = 1;
				roNo = Utility.GetBillNo("",logonUser.getDealerCode(),"RO");
			}else if (Constant.REPAIR_TYPE_03.equals(repairType)) {//售前维修
				startTime = null;
				endTime = null;
				outPerson = null;
				outSite = null;
				outLicenseno = null;
				fromAdress = null;
				endAdress = null;
				outMileage = null;
				campaignCode = null;
				freeTimes = null;
				roNo = Utility.GetBillNo("",logonUser.getDealerCode(),"RO");
			}else if (Constant.REPAIR_TYPE_04.equals(repairType)) {//保养
				wrLabourCodes = null;
				partCodes = null;
				itemCodes = null;
				startTime = null;
				endTime = null;
				outPerson = null;
				outSite = null;
				outLicenseno = null;
				fromAdress = null;
				endAdress = null;
				outMileage = null;
				campaignCode = null;
				TmVehiclePO tvps = new TmVehiclePO();
				tvps.setVin(vin);
				TmVehiclePO tvpsUp = new TmVehiclePO();
				tvpsUp.setVin(vin);
				Date checkDate = new Date();
				if (Utility.testString(guaranteeDate)) {
					checkDate = Utility.getDate(guaranteeDate, 1);
				}else {
					//mileageDouble =Utility.getDouble(inMileage);
					TmVehiclePO tvp = new TmVehiclePO();
					tvp.setVin(vin);
					List<TmVehiclePO> lsv = dao.select(tvp);
					if (lsv!=null) {
						if (lsv.size()>0) {
							tvp = lsv.get(0);
						}
					}
					checkDate = tvp.getPurchasedDate(); //保修改开始时间
				}
				Date now = new Date(); //今天
				if (checkDate!=null) {
					String formatStyle ="yyyy-MM-dd";  
					SimpleDateFormat df = new SimpleDateFormat(formatStyle);  
					String d1 = df.format(checkDate);
					String d2 = df.format(now);
					//month  = Utility.compareDate(d1,d2,1); //取得今日和保养开始时间的插值
					checkday = Utility.compareDate(d1, d2, 0); //取得今日和保养开始时间的插值 天数
				}
				List<TtAsWrQamaintainPO>  listFree =  dao.getFree(Integer.valueOf(freeTimes), companyId, 0, checkday, Double.valueOf(inMileage));
				if (listFree!=null) {
					//存在记录，不需要授权
					if (listFree.size()>0) {
						accredit = Constant.APPROVAL_YN_NO;
					}else {
						accredit = Constant.APPROVAL_YN_YES;
					}
				}else {
					accredit = Constant.APPROVAL_YN_YES;
				}
				roNo = Utility.GetBillNo("",logonUser.getDealerCode(),"RO");
				if (Constant.APPROVAL_YN_NO.toString().equals(String.valueOf(accredit))&&checkDate!=null) { //不需要授权并且不为售前车直接更新车辆表保养次数
					tvpsUp.setFreeTimes(Utility.getInt(freeTimes));
					List<Map<String, Object>> listCount = dao.viewRoNoCount(roNo);
					if(Integer.valueOf(listCount.get(0).get("COUNT").toString())<1){
					dao.update(tvps, tvpsUp);
					}
				}
			}else if (Constant.REPAIR_TYPE_05.equals(repairType)) {//服务活动
				TtAsActivityPO tapo = new TtAsActivityPO();
				tapo.setActivityCode(campaignCode);
				List<TtAsActivityPO> laste = dao.select(tapo);
				if (laste!=null) {
					if (laste.size()>0) {
						tapo = laste.get(0);
					}
				}
				Integer ak = tapo.getActivityKind();
				if (ak!=null) {
					if (ak.toString().equals(Constant.SERVICEACTIVITY_KIND_02.toString())) { //是免费保养类型
						TmVehiclePO tvps = new TmVehiclePO();
						tvps.setVin(vin);
						TmVehiclePO tvpsUp = new TmVehiclePO();
						tvpsUp.setVin(vin);
						tvpsUp.setFreeTimes(Utility.getInt(freeTimes));
						dao.update(tvps, tvpsUp);
					}else {
						freeTimes = null;
					}
				}else {
					freeTimes = null;
				}
				startTime = null;
				endTime = null;
				outPerson = null;
				outSite = null;
				outLicenseno = null;
				fromAdress = null;
				endAdress = null;
				outMileage = null;
				//roNo = SequenceManager.getSequence2(logonUser.getDealerCode()+"HD");
				roNo = Utility.GetBillNo("",logonUser.getDealerCode(),"RO");
				
			}
			Long claimId = Utility.getLong(SequenceManager.getSequence("")); // 产生一个索赔ID
			TtAsRepairOrderPO tawap = new TtAsRepairOrderPO();
			tawap.setDealerId(Long.parseLong(dealerId)); //YH 2010.11.30
			tawap.setTroubleDescriptions(TROUBLE_DESC);
			tawap.setTroubleReason(TROUBLE_REASON);
			tawap.setRemarks(APP_REMARK);
			tawap.setRepairMethod(REPAIR_METHOD);
			tawap.setApprovalYn(accredit);//是否需要预授权
			tawap.setId(claimId);
			//将行驶里程插入tm_vehicle		
			List<Map<String, Object>> listCount1 = dao.viewRoNoCount(roNo);
			if(Integer.valueOf(listCount1.get(0).get("COUNT").toString())<1)
			{
				TmVehiclePO po = new TmVehiclePO();
				TmVehiclePO po1 = new TmVehiclePO();
				po1.setVin(vin);
				po.setMileage(Double.valueOf(inMileage));
				po.setCreateBy(logonUser.getUserId());
				po.setUpdateDate(new Date());
				dao.updateMileage(po1,po);
			}

			//roNo = SequenceManager.getSequence("RO");
			//tawap.setRoNo(SequenceManager.getSequence("RO"));
			tawap.setDealerCode(dealerCode);
			tawap.setRoNo(roNo);
			if (Constant.REPAIR_TYPE_02.equals(repairType)) { //如果是外出
				TtAsWrOutrepairPO to = new TtAsWrOutrepairPO();
				to.setId(Utility.getLong(SequenceManager.getSequence("")));
				to.setRoNo(roNo);
				//to.setStartTime(Utility.getDate(startTime, 3));
				//zhumingwei 2011-03-09
				to.setStartTime(Utility.getDate(hhmm, 3));
				//zhumingwei 2011-03-09
				//to.setEndTime(Utility.getDate(endTime, 3));
				//zhumingwei 2011-03-09
				to.setEndTime(Utility.getDate(hhmm1, 3));
				//zhumingwei 2011-03-09
				to.setOutPerson(outPerson);
				to.setOutSite(outSite);
				to.setOutLicenseno(outLicenseno);
				to.setFromAdress(fromAdress);
				to.setEndAdress(endAdress);
				to.setOutMileage(Utility.getDouble(outMileage));
				to.setCreateBy(logonUser.getUserId());
				to.setCreateDate(date);
				dao.insert(to);
			}
			//tawap.setLineNo(Utility.getInt(lineNo));
			tawap.setVin(vin);
			
			tawap.setRoCreateDate(new Date());
			tawap.setDeliveryDate(Utility.getDate(roEnddate, 1));
			//tawap.setGuaranteeDate(Utility.getDate(guaranteeDate, 1)); 保养开始时间
			tawap.setServiceAdvisor(serveAdvisor);
			tawap.setRepairTypeCode("");  //维修类型
			//tawap.setClaimType(Utility.getInt(claimType));
			tawap.setLicense(licenseNo);
			tawap.setBrand(brandCode);
			//tawap.setBrandName(brandName);
			tawap.setModel(modelCode);
			//tawap.setModelName(modelName);
			tawap.setSeries(seriesCode);
			//tawap.setSeriesName(seriesName);
			tawap.setEngineNo(engineNo);
			tawap.setGuaranteeDate(Utility.getDate(guaranteeDate,1 ));
			tawap.setRemark(remark);
			tawap.setFreeTimes(Utility.getInt(freeTimes));
			//tawap.setApprovalYn(Integer.valueOf(APPROVAL_YN));
			tawap.setInMileage(Utility.getDouble(inMileage));
			tawap.setDeliverer(deliverer);
			tawap.setDelivererPhone(delivererPhone);
			tawap.setDelivererMobile(delivererMobile);
			tawap.setDelivererAdress(delivererAdress);
			tawap.setRepairTypeCode(repairType);
			tawap.setCamCode(campaignCode);
			tawap.setRoStatus(Constant.RO_STATUS_01);
			tawap.setCreateBy(logonUser.getUserId());
			tawap.setCreateDate(date);
			tawap.setAccreditAmount(1);//默认为不同意费用
			if(ownerName!=null&&!ownerName.equals("")){
			tawap.setOwnerName(ownerName);
			}
			if(remark2!=null&&!remark2.equals("")){
				tawap.setRemark2(remark2);
			}
			// 插入时需要对车辆信息表中的车牌号进行更新
			TmVehiclePO tvp = new TmVehiclePO();
			tvp.setVin(vin);
			TmVehiclePO tvpUp = new TmVehiclePO();
			tvpUp.setVin(vin);
			tvpUp.setLicenseNo(licenseNo);
			tvpUp.setPurchasedDate(Utility.getDate(guaranteeDate, 1));
			tvpUp.setUpdateBy(logonUser.getUserId());
			tvpUp.setUpdateDate(date);
			dao.update(tvp, tvpUp);
			// 主工时插入
			if (wrLabourCodes != null) {
				for (int i = 0; i < wrLabourCodes.length; i++) {
					/* if (i == 0) { */
					// 主工时数量和金额
					labourHoursMain += Utility.getFloat(labourHours[i]);
					stdHourAmount += Utility.getDouble(labourAmounts[i]);
					
					// 累加总工时金额
					labourAmountMain += Utility.getDouble(labourAmounts[i]);
					TtAsRoLabourPO tawlp = new TtAsRoLabourPO();
					tawlp.setRoId(claimId);
					tawlp.setId(Utility.getLong(SequenceManager.getSequence("")));
					tawlp.setWrLabourcode(wrLabourCodes[i]);
					tawlp.setWrLabourname(wrLabournames[i]);
					//tawlp.setLabourHours(Utility.getFloat(labourHours[i]));
					tawlp.setStdLabourHour(Utility.getDouble(labourHours[i]));
					tawlp.setLabourPrice(Utility.getFloat(labourPrices[i]));
					tawlp.setLabourAmount(Utility.getDouble(labourAmounts[i]));
					tawlp.setPayType(Utility.getInt(itemPayType[i]));
					tawlp.setActivityCode(campaignCode);
					if (Constant.PAY_TYPE_01==Utility.getInt(itemPayType[i])) {
						tawlp.setChargePartitionCode("");
					}else if (Constant.PAY_TYPE_02==Utility.getInt(itemPayType[i])) {
						tawlp.setChargePartitionCode("S");
					}
					if (Constant.REPAIR_TYPE_05.equals(repairType)) {//如果是服务活动就将活动编码插入配件表和工时表
						tawlp.setActivityCode(activityCode);
						
					}
					
					//tawlp.setBalanceAmount(Utility.getDouble(labourAmounts[i]));
					tawlp.setCreateBy(logonUser.getUserId());
					tawlp.setCreateDate(date);
					dao.insert(tawlp);
					// System.out.println("==========="+wrLabourCodes[i]+"================");
				}
			}

			
			//tawap.setLabourPrice(stdHourAmount);
			//tawap.setLabourHours(labourHoursMain);
			//tawap.setReinforceHours(reinForceHoursMain);
			//tawap.setReinLabourAmount(reinHourAmount);
			tawap.setLabourPrice(Utility.getDouble(""+labourAmountMain));
			/*
			 * if (parts!=null) { tawap.setFailedPartNo(failedPartNo); }
			 */
			// 配件插入
			if (partCodes != null) {
				for (int i = 0; i < partCodes.length; i++) {
					/*
					 * // 第一个配件需要插入到索赔申请单表中 if (i == 0) {
					 * tawap.setFailedPartNo(partCodes[i]); //主损部件 }
					 */
					// 累计配件数量
					partsCount += Utility.getDouble(amounts[i]);
					// 累计配件金额
					partsAmountMain += Utility.getDouble(amounts[i]);
					TtAsRoRepairPartPO tawp = new TtAsRoRepairPartPO();
					
					tawp.setRoId(claimId);
					tawp.setId(Utility.getLong(SequenceManager.getSequence("")));
					tawp.setPartNo(partCodes[i]);
					tawp.setPartName(partNames[i]);
					//tawp.setDownPartCode(downPartCodes[i]);
					//tawp.setDownPartName(downPartNames[i]);
					tawp.setPartQuantity(Utility.getFloat(quantitys[i]));
					tawp.setPartCostPrice(Utility.getDouble(prices[i]));
					tawp.setPartCostAmount(Utility.getDouble(amounts[i]));
					tawp.setPayType(Utility.getInt(partPayType[i]));
					tawp.setActivityCode(campaignCode);
					if (Constant.PAY_TYPE_01==Utility.getInt(partPayType[i])) {
						tawp.setChargePartitionCode("");
					}else if (Constant.PAY_TYPE_02==Utility.getInt(partPayType[i])) {
						tawp.setChargePartitionCode("S");
					}
					//判断是否配件是否在三包范围内
					is_gua = partIsGua(guaranteeDate, inMileage, vin, partCodes[i]);
						tawp.setIsGua(is_gua); //在三包范围内
					if (Constant.REPAIR_TYPE_05.equals(repairType)) {//如果是服务活动就将活动编码插入配件表和工时表
						tawp.setActivityCode(activityCode);
						
					}
					tawp.setCreateBy(logonUser.getUserId());
					tawp.setCreateDate(date);
					//tawp.setRemark(remarks[i]);
					dao.insert(tawp);

					// System.out.println("==========="+wrLabourCodes[i]+"================");
				}
			}
			//tawap.setPartsCount(partsCount);
			tawap.setRepairPartAmount(partsAmountMain);

			// 其他项目插入
			if (itemCodes != null) {
				for (int i = 0; i < itemCodes.length; i++) {
					// 累计其他项目总金额
					netItemAmount += Utility.getDouble(itemAmounts[i]);
					TtAsRoAddItemPO tawp = new TtAsRoAddItemPO();
					tawp.setRoId(claimId);
					tawp.setId(Utility.getLong(SequenceManager.getSequence("")));
					tawp.setAddItemCode(itemCodes[i]);
					tawp.setAddItemName(itemNames[i]);
					tawp.setAddItemAmount(Utility.getDouble(itemAmounts[i]));
					tawp.setRemark(itemRemarks[i]);
					tawp.setActivityCode(campaignCode);
					tawp.setPayType(Utility.getInt(otherPayType[i]));
					if (Constant.PAY_TYPE_01==Utility.getInt(otherPayType[i])) {
						tawp.setChargePartitionCode("");
					}else if (Constant.PAY_TYPE_02==Utility.getInt(otherPayType[i])) {
						tawp.setChargePartitionCode("S");
					}
					//tawp.setBalanceAmount(Utility.getDouble(itemAmounts[i]));
					tawp.setCreateBy(logonUser.getUserId());
					tawp.setCreateDate(date);
					dao.insert(tawp);
					// System.out.println("==========="+wrLabourCodes[i]+"================");
				}
			}
			repairTotal = labourAmountMain + partsAmountMain + netItemAmount;
					//+ campaignFeeDb + freeMPriceDb;
			tawap.setAddItemAmount(netItemAmount);
			tawap.setRepairAmount(repairTotal);
			//tawap.setGrossCredit(repairTotal * 1);// 这里插入总金额 税额暂时设定为1
			//tawap.setStatus(Constant.CLAIM_APPLY_ORD_TYPE_01);
			// 插入到索赔申请单表
			//验证是否有重复工时如果存在就删除一个
			List<Map<String, Object>> listLabour = dao.viewRepeatedlyLabour(claimId);
			String labourCode="";
			if(listLabour.size()>0){
				for(int i=0;i<listLabour.size(); i++){
					labourCode = listLabour.get(i).get("CODE").toString();
					List<Map<String, Object>> listLabourId = dao.viewLabourCode(claimId, labourCode);
					if(listLabourId.size()>0){
						dao.deleteLabourItem(listLabourId.get(0).get("LABOUR_ID").toString(), claimId);
					}
				}
			}
			List<Map<String, Object>> listCount = dao.viewRoNoCount(roNo);
			if(Integer.valueOf(listCount.get(0).get("COUNT").toString())<1){
				dao.insert(tawap);
			
			}	
			act.setOutData("roNo", roNo);
			act.setOutData("ID", claimId);
			if(accredit==0){
				act.setForword(RO_URL);
			}
			else{
			roModifyForward1(String.valueOf(claimId), null);
			}

		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "索赔单维护");
			logger.error(logonUser, e1);
			act.setException(e1);
		}
	}

	/**
	 * 
	 * @Title: roUpdate
	 * @Description: TODO(工单修改)
	 * @param 设定文件
	 * @return void 返回类型
	 * @throws
	 */
	public void roUpdate() {
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean) act.getSession().get(
				Constant.LOGON_USER);
		String dealerId = logonUser.getDealerId();
		StringBuffer con = new StringBuffer();
		Date date = new Date();
		try {

			RequestWrapper request = act.getRequest();
			Integer curPage = request.getParamValue("curPage") != null ? Integer
					.parseInt(request.getParamValue("curPage"))
					: 1; // 处理当前页
			Integer pageSize = 10;
			float labourHoursMain = 0f; // 基本工时数
			float reinForceHoursMain = 0f; // 附加工时数
			double stdHourAmount = 0; // 基本工时金额
			double reinHourAmount = 0; // 附加工时金额
			int partsCount = 0; // 总配件数
			float labourAmountMain = 0; // 总工时金额
			double partsAmountMain = 0; // 配件金额
			double netItemAmount = 0; // 其他项目金额
			double repairTotal = 0; // 索赔申请金额
			String roId = request.getParamValue("roId");
			String ownerName = request.getParamValue("CTM_NAME_1");//车主姓名
			String id = request.getParamValue("ID");
			String roNo = request.getParamValue("RO_NO"); // 工单号
			String lineNo = request.getParamValue("LINE_NO");// 行号
			String roStartdate = request.getParamValue("RO_STARTDATE");// 工单开始时间
			String roEnddate = request.getParamValue("RO_ENDDATE");// 工单结束时间
			String guaranteeDate = request.getParamValue("GUARANTEE_DATE");// 保修开始时间
			String serveAdvisor = request.getParamValue("SERVE_ADVISOR");// 接待员
			String vin = request.getParamValue("VIN");// VIN
			String remark = request.getParamValue("APP_REMARK");// 申请备注
			String claimType = request.getParamValue("CLAIM_TYPE"); // 索赔类型
			String deliverer = request.getParamValue("DELIVERER");
			String delivererPhone = request.getParamValue("DELIVERER_PHONE");
			String delivererMobile = request.getParamValue("DELIVERER_MOBILE");
			String delivererAdress = request.getParamValue("DELIVERER_ADRESS");
			String repairType = request.getParamValue("REPAIR_TYPE"); //维修类型
			String APPROVAL_YN = request.getParamValue("APPROVAL_YN");
			String TROUBLE_DESC = request.getParamValue("TROUBLE_DESC");//故障描述
			String TROUBLE_REASON = request.getParamValue("TROUBLE_REASON");//故障原因
			String REPAIR_METHOD = request.getParamValue("REPAIR_METHOD");//故障措施
			String APP_REMARK = request.getParamValue("APP_REMARK");//申请备注
			/*外出维修*/
			String startTime = request.getParamValue("START_DATE");
			String endTime = request.getParamValue("END_DATE");
			String outPerson = request.getParamValue("OUT_PERSON");
			String outSite = request.getParamValue("OUT_SITE");
			String outLicenseno = request.getParamValue("OUT_LICENSENO");
			String fromAdress = request.getParamValue("FROM_ADRESS");
			String endAdress = request.getParamValue("END_ADRESS");
			String outMileage = request.getParamValue("OUT_MILEAGE");
			/*
			 * String damageType = request.getParamValue("DAMAGE_TYPE"); // 质损类型
			 * String damageArea = request.getParamValue("DAMAGE_AREA"); // 质损区域
			 * String damageDegree = request.getParamValue("DAMAGE_DEGREE"); //
			 * 质损程度 String troubleCode = request.getParamValue("TROUBLE_CODE"); //
			 * 故障代码
			 */String troubleDesc = request.getParamValue("TROUBLE_DESC");
			String troubleReason = request.getParamValue("TROUBLE_REASON");
			String repairMethod = request.getParamValue("REPAIR_METHOD");
			String inMileage = request.getParamValue("IN_MILEAGE");
			String dealerCode = request.getParamValue("DEALER_CODE");

			String campaignCode = request.getParamValue("CAMPAIGN_CODE"); // 服务活动代码
			String campaignFee = request.getParamValue("CAMPAIGN_FEE"); // 服务活动费用
			String isFixing = request.getParamValue("IS_FIX"); // 服务活动是否固定费用1为固定费用
			String remark2 = request.getParamValue("remark_ysq");//获取预授权申请内容
			String freeMAmount = request.getParamValue("FREE_M_AMOUNT"); // 免费保养次数
			String freeMPrice = request.getParamValue("FREE_M_PRICE"); // 免费保养费用
			String freeTimes = request.getParamValue("freeTimes"); //免费保养次数

			String yieldly = request.getParamValue("YIELDLY"); // 产地
			String licenseNo = request.getParamValue("LICENSE_NO"); // 车牌号
			String brandCode = request.getParamValue("BRAND_CODE0"); // 品牌
			String brandName = request.getParamValue("BRAND_NAME0");
			String modelCode = request.getParamValue("MODEL_CODE0"); // 车型
			String modelName = request.getParamValue("MODEL_NAME0");
			String seriesCode = request.getParamValue("SERIES_CODE0");// 车系
			String seriesName = request.getParamValue("SERIES_NAME0");
			String engineNo = request.getParamValue("ENGINE_NO");
			String gearboxNo = request.getParamValue("GEARBOX_NO0"); // 变速箱
			String rearaxleNo = request.getParamValue("REARAXLE_NO0"); // 后桥
			String transferNo = request.getParamValue("TRANSFER_NO0"); // 分动器
			// Long claimId = Utility.getLong(SequenceManager.getSequence(""));
			// // 产生一个索赔ID

			// 取得删除IDS
			String itemDel = request.getParamValue("ITEM_DEL");
			String[] labourIds = request.getParamValues("LABOUR_ID");
			String[] items = request.getParamValues("ITEM"); // 工时选择的CHECKBOX
			String[] wrLabourCodes = request.getParamValues("WR_LABOURCODE"); // 获取工时代码
			String[] wrLabournames = request.getParamValues("WR_LABOURNAME"); // 获取工时名称
			String[] labourHours = request.getParamValues("LABOUR_HOURS"); // 获取工时数
			String[] labourPrices = request.getParamValues("LABOUR_PRICE"); // 获取工时单价
			String[] labourAmounts = request.getParamValues("LABOUR_AMOUNT"); // 获取工时金额
			String[] damageType = request.getParamValues("DAMAGE_TYPE"); // 质损类型
			String[] damageArea = request.getParamValues("DAMAGE_AREA"); // 质损区域
			String[] damageDegree = request.getParamValues("DAMAGE_DEGREE"); // 质损程度
			String[] troubleCode = request.getParamValues("TROUBLE_CODE"); // 故障代码
			String[] itemIsFore = request.getParamValues("ITEM_IS_FORE");//是否授权
			String[] itemPayType = request.getParamValues("PAY_TYPE_ITEM");//付费方式

			// 附加工时
			String[] bMlCode = request.getParamValues("B_ML_CODE");
			String[] labourIds0 = request.getParamValues("LABOUR_ID0"); // 附加工时ID
			String[] wrLabourCodes0 = request.getParamValues("WR_LABOURCODE0"); // 获取工时代码
			String[] wrLabournames0 = request.getParamValues("WR_LABOURNAME0"); // 获取工时名称
			String[] labourHours0 = request.getParamValues("LABOUR_HOURS0"); // 获取工时数
			String[] labourPrices0 = request.getParamValues("LABOUR_PRICE0"); // 获取工时单价
			String[] labourAmounts0 = request.getParamValues("LABOUR_AMOUNT0"); // 获取工时金额

			//
			String partDel = request.getParamValue("PART_DEL");
			String[] partIds = request.getParamValues("PART_ID"); // 取得PARTid
			String[] parts = request.getParamValues("PART");// 配件选择的CHECKBOX
			String[] partCodes = request.getParamValues("PART_CODE"); // 上件代码
			String[] partNames = request.getParamValues("PART_NAME"); // 上件名称
			String[] downPartCodes = request.getParamValues("DOWN_PART_CODE"); // 下件代码
			String[] downPartNames = request.getParamValues("DOWN_PART_NAME"); // 下件名称
			String[] quantitys = request.getParamValues("QUANTITY"); // 上件数量
			String[] prices = request.getParamValues("PRICE"); // 单价
			String[] amounts = request.getParamValues("AMOUNT"); // 数量
			String[] supplierCodes = request.getParamValues("PRODUCER_CODE");// 生产商代码
			String[] supplierNames = request.getParamValues("PRODUCER_NAME"); // 生产商名称
			String[] downSupplierCodes = request.getParamValues("PRODUCER_CODE1");// 生产商代码
			String[] downSupplierNames = request.getParamValues("PRODUCER_NAME1"); // 生产商名称
			String[] remarks = request.getParamValues("REMARK"); // 故障描述
			String[] appTime = request.getParamValues("appTime"); // 索赔工时
			String[] bMpCode = request.getParamValues("B_MP_CODE");// 所属主配件
			String[] partIsFore = request.getParamValues("PART_IS_FORE");//是否授权
			String[] partPayType = request.getParamValues("PAY_TYPE_PART"); //配件付费方式
			String[] isGua = request.getParamValues("IS_GUA");
			String otherDel = request.getParamValue("OTHER_DEL");
			String[] itemIds = request.getParamValues("OTHER_ID");
			String[] itemCodes = request.getParamValues("ITEM_CODE"); // 其他项目代码
			String[] itemNames = request.getParamValues("ITEM_NAME"); // 其他项目名称
			String[] itemAmounts = request.getParamValues("ITEM_AMOUNT");// 其他项目金额
			String[] itemRemarks = request.getParamValues("ITEM_REMARK");// 备注
			String[] otherIsFore = request.getParamValues("OTHER_IS_FORE");//是否授权
			String[] otherPayType = request.getParamValues("PAY_TYPE_OTHER"); //其他付费方式
			//将行驶里程插入tm_vehicle	--mileage	
			int is_gua = 0;//配件是否三包
			int accredit = 0;//是否预授权
			List<Map<String, Object>> mileageList = dao.viewFreeTime1(vin);
			Double mileage = Double.valueOf(mileageList.get(0).get("MILEAGE").toString());
			if(mileage<Double.valueOf(inMileage)){
				TmVehiclePO po = new TmVehiclePO();
				TmVehiclePO po1 = new TmVehiclePO();
				po1.setVin(vin);
				po.setMileage(Double.valueOf(inMileage));
				po.setCreateBy(logonUser.getUserId());
				po.setUpdateDate(new Date());
				dao.updateMileage(po1,po);
			}
			//将行驶里程更新到tm_vehicle
			// 删除附件ID
			// String attIds = request.getParamValue("attIds");
			String[] attIds = request.getParamValues("uploadFjid");
			if (Constant.REPAIR_TYPE_01.equals(repairType)) {//一般维修
				startTime = null;
				endTime = null;
				outPerson = null;
				outSite = null;
				outLicenseno = null;
				fromAdress = null;
				endAdress = null;
				outMileage = null;
				campaignCode = null;
				freeTimes = null;
			}else if (Constant.REPAIR_TYPE_02.equals(repairType)) {//外出维修
				campaignCode = null;
				freeTimes = null;
				accredit = 1;
			}else if (Constant.REPAIR_TYPE_03.equals(repairType)) {//售前维修
				startTime = null;
				endTime = null;
				outPerson = null;
				outSite = null;
				outLicenseno = null;
				fromAdress = null;
				endAdress = null;
				outMileage = null;
				campaignCode = null;
				freeTimes = null;
			}else if (Constant.REPAIR_TYPE_04.equals(repairType)) {//保养
				wrLabourCodes = null;
				partCodes = null;
				itemCodes = null;
				startTime = null;
				endTime = null;
				outPerson = null;
				outSite = null;
				outLicenseno = null;
				fromAdress = null;
				endAdress = null;
				outMileage = null;
				campaignCode = null;
				TmVehiclePO tvps = new TmVehiclePO();
				tvps.setVin(vin);
				TmVehiclePO tvpsUp = new TmVehiclePO();
				tvpsUp.setVin(vin);
				if (Constant.APPROVAL_YN_NO.toString().equals(APPROVAL_YN)) { //不需要授权直接更新车辆表保养次数
					tvpsUp.setFreeTimes(Utility.getInt(freeTimes));
					dao.update(tvps, tvpsUp);
				}
				accredit = isFree(vin, mileage, Long.valueOf(logonUser.getCompanyId()));
			}else if (Constant.REPAIR_TYPE_05.equals(repairType)) {//服务活动
				startTime = null;
				endTime = null;
				outPerson = null;
				outSite = null;
				outLicenseno = null;
				fromAdress = null;
				endAdress = null;
				outMileage = null;
				TtAsActivityPO tapo = new TtAsActivityPO();
				tapo.setActivityCode(campaignCode);
				List<TtAsActivityPO> laste = dao.select(tapo);
				if (laste!=null) {
					if (laste.size()>0) {
						tapo = laste.get(0);
					}
				}
				Integer ak = tapo.getActivityKind();
				if (ak!=null) {
					if (ak.toString().equals(Constant.SERVICEACTIVITY_KIND_02.toString())) { //是免费保养类型
						TmVehiclePO tvps = new TmVehiclePO();
						tvps.setVin(vin);
						TmVehiclePO tvpsUp = new TmVehiclePO();
						tvpsUp.setVin(vin);
						tvpsUp.setFreeTimes(Utility.getInt(freeTimes));
						dao.update(tvps, tvpsUp);
					}else {
						freeTimes = null;
					}
				}else {
					freeTimes = null;
				}
				//freeTimes = null;
			}
			// 索赔单ID
			Long claimId = Utility.getLong(id);
			
			//Double campaignFeeDb = Utility.getDouble(campaignFee);
			//Double freeMPriceDb = Utility.getDouble(freeMPrice);
			
			TtAsRepairOrderPO tawap0 = new TtAsRepairOrderPO();
			tawap0.setId(claimId);
			TtAsRepairOrderPO tawap = new TtAsRepairOrderPO();
			tawap.setId(claimId);
			// tawap.setClaimNo(SequenceManager.getSequence("CO"));
			tawap.setDealerCode("");
			tawap.setRoNo(roNo);
			if (Constant.REPAIR_TYPE_02.equals(repairType)) { //如果是外出
				TtAsWrOutrepairPO to0 = new TtAsWrOutrepairPO();
				to0.setRoNo(roNo);
				List toLs = dao.select(to0);
				if (toLs!=null) {
					if (toLs.size()>0) {
						TtAsWrOutrepairPO to = new TtAsWrOutrepairPO();
						to.setId(Utility.getLong(SequenceManager.getSequence("")));
						to.setRoNo(roNo);
						to.setStartTime(Utility.getDate(startTime, 3));
						to.setEndTime(Utility.getDate(endTime, 3));
						to.setOutPerson(outPerson);
						to.setOutSite(outSite);
						to.setOutLicenseno(outLicenseno);
						to.setFromAdress(fromAdress);
						to.setEndAdress(endAdress);
						to.setOutMileage(Utility.getDouble(outMileage));
						to.setUpdateBy(logonUser.getUserId());
						to.setUpdateDate(date);
						dao.update(to0, to);
					}else {
						TtAsWrOutrepairPO to = new TtAsWrOutrepairPO();
						to.setId(Utility.getLong(SequenceManager.getSequence("")));
						to.setRoNo(roNo);
						to.setStartTime(Utility.getDate(startTime, 3));
						to.setEndTime(Utility.getDate(endTime, 3));
						to.setOutPerson(outPerson);
						to.setOutSite(outSite);
						to.setOutLicenseno(outLicenseno);
						to.setFromAdress(fromAdress);
						to.setEndAdress(endAdress);
						to.setOutMileage(Utility.getDouble(outMileage));
						to.setCreateBy(logonUser.getUserId());
						to.setCreateDate(date);
						dao.insert(to);
					}
				}else {
					TtAsWrOutrepairPO to = new TtAsWrOutrepairPO();
					to.setId(Utility.getLong(SequenceManager.getSequence("")));
					to.setRoNo(roNo);
					to.setStartTime(Utility.getDate(startTime, 3));
					to.setEndTime(Utility.getDate(endTime, 3));
					to.setOutPerson(outPerson);
					to.setOutSite(outSite);
					to.setOutLicenseno(outLicenseno);
					to.setFromAdress(fromAdress);
					to.setEndAdress(endAdress);
					to.setOutMileage(Utility.getDouble(outMileage));
					to.setCreateBy(logonUser.getUserId());
					to.setCreateDate(date);
					dao.insert(to);
				}
			}
			tawap.setVin(vin);
			tawap.setTroubleDescriptions(TROUBLE_DESC);
			tawap.setTroubleReason(TROUBLE_REASON);
			tawap.setRemarks(APP_REMARK);
			tawap.setRepairMethod(REPAIR_METHOD);
			tawap.setDealerCode(dealerCode);
			//tawap.setRoCreateDate(Utility.getDate(roStartdate, 1));
			tawap.setDeliveryDate(Utility.getDate(roEnddate, 1));
			//tawap.setGuaranteeDate(Utility.getDate(guaranteeDate, 1));
			tawap.setServiceAdvisor(serveAdvisor);
			tawap.setRepairTypeCode(repairType);  //维修类型
			tawap.setLicense(licenseNo);
			tawap.setBrand(brandCode);
			//tawap.setBrandName(brandName);
			tawap.setModel(modelCode);
			//tawap.setModelName(modelName);
			tawap.setSeries(seriesCode);
			//tawap.setSeriesName(seriesName);
			tawap.setEngineNo(engineNo);
			tawap.setDeliverer(deliverer);
			tawap.setDelivererPhone(delivererPhone);
			tawap.setDelivererMobile(delivererMobile);
			tawap.setDelivererAdress(delivererAdress);
			tawap.setFreeTimes(Utility.getInt(freeTimes));
			/*tawap.setGearboxNo(gearboxNo);
			tawap.setRearaxleNo(rearaxleNo);
			tawap.setTransferNo(transferNo);
			tawap.setYieldly(yieldly);*/
			tawap.setGuaranteeDate(Utility.getDate(guaranteeDate,1 ));
			tawap.setRepairTypeCode(repairType);
			tawap.setCamCode(campaignCode);
			tawap.setRemark(remark);
			tawap.setInMileage(Utility.getDouble(inMileage));
			tawap.setUpdateBy(logonUser.getUserId());
			tawap.setUpdateDate(date);
			if(ownerName!=null&&!ownerName.equals("")){
				tawap.setOwnerName(ownerName);
			}
			
			if(remark2!=null&&!remark2.equals("")){
				tawap.setRemark2(remark2);
			}
			// 插入时需要对车辆信息表中的车牌号进行更新
			TmVehiclePO tvp = new TmVehiclePO();
			tvp.setVin(vin);
			TmVehiclePO tvpUp = new TmVehiclePO();
			tvpUp.setVin(vin);
			tvpUp.setLicenseNo(licenseNo);
			tvpUp.setUpdateBy(logonUser.getUserId());
			tvpUp.setUpdateDate(date);
			dao.update(tvp, tvpUp);

			// 如果有删除的
			if (Utility.testString(itemDel)) {
				itemDel = itemDel.replaceFirst(",", "");
				String[] itemDels = itemDel.split(",");
				Set<String> itemSet = new HashSet<String>();
				// 避免重复ID
				for (int i = 0; i < itemDels.length; i++) {
					itemSet.add(itemDels[i]);
				}
				Iterator<String> it = itemSet.iterator();
				while (it.hasNext()) {
					TtAsRoLabourPO t = new TtAsRoLabourPO();
					t.setId(Utility.getLong(it.next()));
					dao.delete(t);
				}

			}
			// 如果隐藏域中的labourId不是空（主工时）更新工时
			if (labourIds != null) {
				for (int i = 0; i < labourIds.length; i++) {
					// 主工时数量和金额
					labourHoursMain += Utility.getFloat(labourHours[i]);
					stdHourAmount += Utility.getDouble(labourAmounts[i]);
					// 累加附加工时数量和金额
					// reinForceHoursMain += Utility.getFloat(labourHours[i]);
					// reinHourAmount += Utility.getDouble(labourAmounts[i]);
					// 累加总工时金额
					labourAmountMain += Utility.getDouble(labourAmounts[i]);
					TtAsRoLabourPO tawlp0 = new TtAsRoLabourPO();
					tawlp0.setId(Utility.getLong(labourIds[i]));
					TtAsRoLabourPO tawlp = new TtAsRoLabourPO();
					
					tawlp.setId(Utility.getLong(labourIds[i]));
					tawlp.setRoId(claimId);
					tawlp.setWrLabourcode(wrLabourCodes[i]);
					tawlp.setWrLabourname(wrLabournames[i]);
					tawlp.setStdLabourHour(Utility.getDouble(labourHours[i]));
					tawlp.setLabourPrice(Utility.getFloat(labourPrices[i]));
					tawlp.setLabourAmount(Utility.getDouble(labourAmounts[i]));
					tawlp.setPayType(Utility.getInt(itemPayType[i]));
					tawlp.setActivityCode(campaignCode);
					if (Constant.PAY_TYPE_01==Utility.getInt(itemPayType[i])) {
						tawlp.setChargePartitionCode("");
					}else if (Constant.PAY_TYPE_02==Utility.getInt(itemPayType[i])) {
						tawlp.setChargePartitionCode("S");
					}
					tawlp.setUpdateBy(logonUser.getUserId());
					tawlp.setUpdateDate(date);
					dao.update(tawlp0, tawlp);
				}
				// 工时插入
				// 如果工时代码多多于有ID的代码，证明新增了工时（主工时）
				if (wrLabourCodes.length > labourIds.length) {
					for (int i = labourIds.length; i < wrLabourCodes.length; i++) {
						// 累加附加工时数量和金额
						// reinForceHoursMain +=
						// Utility.getFloat(labourHours[i]);
						// reinHourAmount +=
						// Utility.getDouble(labourAmounts[i]);
						// 主工时数量和金额
						labourHoursMain += Utility.getFloat(labourHours[i]);
						stdHourAmount += Utility.getDouble(labourAmounts[i]);
						// 累加总工时金额
						labourAmountMain += Utility.getDouble(labourAmounts[i]);
						TtAsRoLabourPO tawlp = new TtAsRoLabourPO();
						tawlp.setRoId(claimId);
						tawlp.setId(Utility.getLong(SequenceManager
								.getSequence("")));
						tawlp.setStdLabourHour(Utility.getDouble(labourHours[i]));
						tawlp.setWrLabourcode(wrLabourCodes[i]);
						tawlp.setWrLabourname(wrLabournames[i]);
						tawlp.setLabourPrice(Utility.getFloat(labourPrices[i]));
						tawlp.setLabourAmount(Utility.getDouble(labourAmounts[i]));
						tawlp.setPayType(Utility.getInt(itemPayType[i]));
						tawlp.setActivityCode(campaignCode);
						if (Constant.PAY_TYPE_01==Utility.getInt(itemPayType[i])) {
							tawlp.setChargePartitionCode("");
						}else if (Constant.PAY_TYPE_02==Utility.getInt(itemPayType[i])) {
							tawlp.setChargePartitionCode("S");
						}
						tawlp.setCreateBy(logonUser.getUserId());
						tawlp.setCreateDate(date);
						dao.insert(tawlp);
					}
				}
				// labourIds如果为空（全部为新增）
			} else {
				if (wrLabourCodes != null) {
					for (int i = 0; i < wrLabourCodes.length; i++) {
						/* if (i == 0) { */
						// 主工时数量和金额
						labourHoursMain = Utility.getFloat(labourHours[i]);
						stdHourAmount = Utility.getDouble(labourAmounts[i]);
						// 累加总工时金额
						labourAmountMain += Utility.getFloat(labourAmounts[i]);
						TtAsRoLabourPO tawlp = new TtAsRoLabourPO();
						
						tawlp.setRoId(claimId);
						tawlp.setId(Utility.getLong(SequenceManager
								.getSequence("")));
						tawlp.setWrLabourcode(wrLabourCodes[i]);
						tawlp.setWrLabourname(wrLabournames[i]);
						tawlp.setStdLabourHour(Utility.getDouble(labourHours[i]));
						tawlp.setLabourPrice(Utility.getFloat(labourPrices[i]));
						tawlp.setLabourAmount(Utility.getDouble(labourAmounts[i]));
						tawlp.setPayType(Utility.getInt(itemPayType[i]));
						tawlp.setActivityCode(campaignCode);
						if (Constant.PAY_TYPE_01==Utility.getInt(itemPayType[i])) {
							tawlp.setChargePartitionCode("");
						}else if (Constant.PAY_TYPE_02==Utility.getInt(itemPayType[i])) {
							tawlp.setChargePartitionCode("S");
						}
						tawlp.setCreateBy(logonUser.getUserId());
						tawlp.setCreateDate(date);
						dao.insert(tawlp);
					}
				}
			}
			
			tawap.setLabourPrice(Utility.getDouble(""+labourAmountMain));

			// 删除配件
			if (Utility.testString(partDel)) {
				partDel = partDel.replaceFirst(",", "");
				String[] partDels = partDel.split(",");
				Set<String> partSet = new HashSet<String>();
				// 避免重复ID
				for (int i = 0; i < partDels.length; i++) {
					partSet.add(partDels[i]);
				}
				Iterator<String> it = partSet.iterator();
				while (it.hasNext()) {
					TtAsRoRepairPartPO t = new TtAsRoRepairPartPO();
					t.setId(Utility.getLong(it.next()));
					dao.delete(t);
				}

			}
			// 配件插入(存在配件ID的更新)
			if (partIds != null) {
				for (int i = 0; i < partIds.length; i++) {
					/*
					 * // 第一个配件需要插入到索赔申请单表中 if (i == 0) {
					 * tawap.setFailedPartNo(partCodes[i]); }
					 */
					// 累计配件数量
					partsCount += Utility.getDouble(amounts[i]);
					// 累计配件金额
					partsAmountMain += Utility.getDouble(amounts[i]);
					TtAsRoRepairPartPO tawp0 = new TtAsRoRepairPartPO();
					tawp0.setId(Utility.getLong(partIds[i]));
					TtAsRoRepairPartPO tawp = new TtAsRoRepairPartPO();
					/*
					 * if (i == 0) {
					 * tawp.setIsMainpart(Constant.IS_MAIN_TROUBLE); } else {
					 * tawp.setIsMainpart(Constant.IS_NOT_MAIN_TROUBLE); }
					 */
					tawp.setId(Utility.getLong(partIds[i]));
					tawp.setRoId(claimId);
					tawp.setPartNo(partCodes[i]);
					tawp.setPartName(partNames[i]);
					
					tawp.setPartQuantity(Utility.getFloat(quantitys[i]));
					tawp.setPartCostPrice(Utility.getDouble(prices[i]));
					tawp.setPartCostAmount(Utility.getDouble(amounts[i]));
					tawp.setPayType(Utility.getInt(partPayType[i]));
					tawp.setActivityCode(campaignCode);
					if (Constant.PAY_TYPE_01==Utility.getInt(partPayType[i])) {
						tawp.setChargePartitionCode("");
					}else if (Constant.PAY_TYPE_02==Utility.getInt(partPayType[i])) {
						tawp.setChargePartitionCode("S");
					}
					is_gua = partIsGua(guaranteeDate, inMileage, vin, partCodes[i]);
					tawp.setIsGua(is_gua); //在三包范围内
					tawp.setUpdateBy(logonUser.getUserId());
					tawp.setUpdateDate(date);
					//tawp.setRemark(remarks[i]);
					dao.update(tawp0, tawp);
				}
				// 如果partCodes的长度大于partIds则说明新增了配件
				if (partCodes.length > partIds.length) {
					for (int i = partIds.length; i < partCodes.length; i++) {
						/*
						 * // 第一个配件需要插入到索赔申请单表中 if (i == 0) {
						 * tawap.setFailedPartNo(partCodes[i]); }
						 */
						// 累计配件数量
						partsCount += Utility.getDouble(amounts[i]);
						// 累计配件金额
						partsAmountMain += Utility.getDouble(amounts[i]);

						TtAsRoRepairPartPO tawp = new TtAsRoRepairPartPO();
						
						tawp.setRoId(claimId);
						tawp.setId(Utility.getLong(SequenceManager
								.getSequence("")));
						tawp.setPartNo(partCodes[i]);
						tawp.setPartName(partNames[i]);
						
						tawp.setPartQuantity(Utility.getFloat(quantitys[i]));
						tawp.setPartCostPrice(Utility.getDouble(prices[i]));
						tawp.setPartCostAmount(Utility.getDouble(amounts[i]));
						tawp.setPayType(Utility.getInt(partPayType[i]));
						tawp.setActivityCode(campaignCode);
						if (Constant.PAY_TYPE_01==Utility.getInt(partPayType[i])) {
							tawp.setChargePartitionCode("");
						}else if (Constant.PAY_TYPE_02==Utility.getInt(partPayType[i])) {
							tawp.setChargePartitionCode("S");
						}
						is_gua = partIsGua(guaranteeDate, inMileage, vin, partCodes[i]);
						tawp.setIsGua(is_gua); //在三包范围内
						tawp.setCreateBy(logonUser.getUserId());
						tawp.setCreateDate(date);
						//tawp.setRemark(remarks[i]);
						dao.insert(tawp);

						// System.out.println("==========="+wrLabourCodes[i]+"================");
					}
				}
				// 如果没有partIds则全部新增操作
			} else {
				if (partCodes != null) {
					for (int i = 0; i < partCodes.length; i++) {
						/*
						 * // 第一个配件需要插入到索赔申请单表中 if (i == 0) {
						 * tawap.setFailedPartNo(partCodes[i]); }
						 */
						// 累计配件数量
						partsCount += Utility.getDouble(amounts[i]);
						// 累计配件金额
						partsAmountMain += Utility.getDouble(amounts[i]);
						TtAsRoRepairPartPO tawp = new TtAsRoRepairPartPO();
						
						
						tawp.setRoId(claimId);
						tawp.setId(Utility.getLong(SequenceManager
								.getSequence("")));
						tawp.setPartNo(partCodes[i]);
						tawp.setPartName(partNames[i]);
						tawp.setPartQuantity(Utility.getFloat(quantitys[i]));
						tawp.setPartCostPrice(Utility.getDouble(prices[i]));
						tawp.setPartCostAmount(Utility.getDouble(amounts[i]));
						tawp.setPayType(Utility.getInt(partPayType[i]));
						tawp.setActivityCode(campaignCode);
						if (Constant.PAY_TYPE_01==Utility.getInt(partPayType[i])) {
							tawp.setChargePartitionCode("");
						}else if (Constant.PAY_TYPE_02==Utility.getInt(partPayType[i])) {
							tawp.setChargePartitionCode("S");
						}
						is_gua = partIsGua(guaranteeDate, inMileage, vin, partCodes[i]);
						tawp.setIsGua(is_gua); //在三包范围内
						tawp.setCreateBy(logonUser.getUserId());
						tawp.setCreateDate(date);
						//tawp.setRemark(remarks[i]);
						dao.insert(tawp);

						// System.out.println("==========="+wrLabourCodes[i]+"================");
					}
				}
			}
			
			tawap.setRepairPartAmount(partsAmountMain);
			/*tawap.setPartsCount(partsCount);
			tawap.setPartAmount(partsAmountMain);*/

			// 删除其他项目
			if (Utility.testString(otherDel)) {
				otherDel = otherDel.replaceFirst(",", "");
				String[] otherDels = otherDel.split(",");
				Set<String> otherSet = new HashSet<String>();
				// 避免重复ID
				for (int i = 0; i < otherDels.length; i++) {
					otherSet.add(otherDels[i]);
				}
				Iterator<String> it = otherSet.iterator();
				while (it.hasNext()) {
					TtAsRoAddItemPO t = new TtAsRoAddItemPO();
					t.setId(Utility.getLong(it.next()));
					dao.delete(t);
				}

			}
			// 其他项目插入
			if (itemIds != null) {
				for (int i = 0; i < itemIds.length; i++) {
					// 累计其他项目总金额
					netItemAmount += Utility.getDouble(itemAmounts[i]);
					TtAsRoAddItemPO tawp0 = new TtAsRoAddItemPO();
					tawp0.setId(Utility.getLong(itemIds[i]));
					TtAsRoAddItemPO tawp = new TtAsRoAddItemPO();
					tawp.setRoId(claimId);
					tawp.setId(Utility.getLong(itemIds[i]));
					
					tawp.setAddItemCode(itemCodes[i]);
					tawp.setAddItemName(itemNames[i]);
					tawp.setAddItemAmount(Utility.getDouble(itemAmounts[i]));
					tawp.setRemark(itemRemarks[i]);
					tawp.setPayType(Utility.getInt(otherPayType[i]));
					tawp.setActivityCode(campaignCode);
					if (Constant.PAY_TYPE_01==Utility.getInt(otherPayType[i])) {
						tawp.setChargePartitionCode("");
					}else if (Constant.PAY_TYPE_02==Utility.getInt(otherPayType[i])) {
						tawp.setChargePartitionCode("S");
					}
					tawp.setUpdateBy(logonUser.getUserId());
					tawp.setUpdateDate(date);
					dao.update(tawp0, tawp);
				}
				if (itemCodes.length > itemIds.length) {
					for (int i = itemIds.length; i < itemCodes.length; i++) {
						// 累计其他项目总金额
						netItemAmount += Utility.getDouble(itemAmounts[i]);
						TtAsRoAddItemPO tawp = new TtAsRoAddItemPO();
						tawp.setRoId(claimId);
						tawp.setId(Utility.getLong(SequenceManager
								.getSequence("")));
						tawp.setAddItemCode(itemCodes[i]);
						tawp.setAddItemName(itemNames[i]);
						tawp.setAddItemAmount(Utility.getDouble(itemAmounts[i]));
						tawp.setRemark(itemRemarks[i]);
						tawp.setPayType(Utility.getInt(otherPayType[i]));
						tawp.setActivityCode(campaignCode);
						if (Constant.PAY_TYPE_01==Utility.getInt(otherPayType[i])) {
							tawp.setChargePartitionCode("");
						}else if (Constant.PAY_TYPE_02==Utility.getInt(otherPayType[i])) {
							tawp.setChargePartitionCode("S");
						}
						tawp.setCreateBy(logonUser.getUserId());
						tawp.setCreateDate(date);
						dao.insert(tawp);
					}
				}
				// 如果为空，则全部为新增
			} else {
				if (itemCodes != null) {
					for (int i = 0; i < itemCodes.length; i++) {
						// 累计其他项目总金额
						netItemAmount += Utility.getDouble(itemAmounts[i]);
						TtAsRoAddItemPO tawp = new TtAsRoAddItemPO();
						tawp.setRoId(claimId);
						tawp.setId(Utility.getLong(SequenceManager
								.getSequence("")));
						tawp.setAddItemCode(itemCodes[i]);
						tawp.setAddItemName(itemNames[i]);
						tawp.setAddItemAmount(Utility.getDouble(itemAmounts[i]));
						tawp.setRemark(itemRemarks[i]);
						tawp.setPayType(Utility.getInt(otherPayType[i]));
						tawp.setActivityCode(campaignCode);
						if (Constant.PAY_TYPE_01==Utility.getInt(otherPayType[i])) {
							tawp.setChargePartitionCode("");
						}else if (Constant.PAY_TYPE_02==Utility.getInt(otherPayType[i])) {
							tawp.setChargePartitionCode("S");
						}
						tawp.setCreateBy(logonUser.getUserId());
						tawp.setCreateDate(date);
						dao.insert(tawp);
					}
				}
			}
			repairTotal = labourAmountMain + partsAmountMain + netItemAmount;
			//+ campaignFeeDb + freeMPriceDb;
			tawap.setAddItemAmount(netItemAmount);
			tawap.setRepairAmount(repairTotal);
			//验证是否有重复工时如果存在就删除一个
			List<Map<String, Object>> listLabour = dao.viewRepeatedlyLabour(claimId);
			String labourCode="";
			if(listLabour.size()>0){
				for(int i=0;i<listLabour.size(); i++){
					labourCode = listLabour.get(i).get("CODE").toString();
					List<Map<String, Object>> listLabourId = dao.viewLabourCode(claimId, labourCode);
					if(listLabourId.size()>0){
						dao.deleteLabourItem(listLabourId.get(0).get("LABOUR_ID").toString(), claimId);
					}
				}
			}
			// 插入到索赔申请单表
			dao.update(tawap0, tawap);
			act.setOutData("success", true);
			roForward();
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "索赔单维护");
			act.setOutData("success", false);
			logger.error(logonUser, e1);
			act.setException(e1);
		}
	}
	/**
	 * 
	* @Title: queryRepairOrder 
	* @Description: TODO(查询工单) 
	* @param     设定文件 
	* @return void    返回类型 
	* @throws
	 */
	public void queryRepairOrder() {
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean) act.getSession().get(
				Constant.LOGON_USER);
		String dealerId = logonUser.getDealerId();
		String dealerCode = logonUser.getDealerCode();
		try {
			RequestWrapper request = act.getRequest();
			Integer curPage = request.getParamValue("curPage") != null ? Integer
					.parseInt(request.getParamValue("curPage"))
					: 1; // 处理当前页
			String roNo = request.getParamValue("RO_NO");
			String vin = request.getParamValue("VIN");
			String repairType = request.getParamValue("REPAIR_TYPE");
			String roCreateDate = request.getParamValue("RO_CREATE_DATE");
			String deliveryDate = request.getParamValue("DELIVERY_DATE");
			String isForl = request.getParamValue("RO_FORE");
			String roStatus =request.getParamValue("RO_STATUS");
			String createDateStr = request.getParamValue("CREATE_DATE_STR");
			String createDateEnd = request.getParamValue("CREATE_DATE_END");
			Map<String,String> map = new HashMap();
			map.put("roNo", roNo);
			map.put("vin", vin);
			map.put("repairType", repairType);
			map.put("roCreateDate", roCreateDate);
			map.put("deliveryDate", deliveryDate);
			map.put("isForl", isForl);
			map.put("roStatus", roStatus);
			map.put("dealerId", dealerId);
			map.put("createDateStr", createDateStr);
			map.put("createDateEnd", createDateEnd);
			PageResult<TtAsRepairOrderExtPO> ps = dao.queryRepairOrderNew(map,Constant.PAGE_SIZE,curPage);
			act.setOutData("ps", ps);
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "索赔单维护");
			logger.error(logonUser, e1);
			act.setException(e1);
		}
	}
	
	/**
	 * Iverson add with 2010-11-12
	 * @Title: queryRepairOrderDelete 
	 * @Description: TODO(查询工单可删除) 
	 * @param     设定文件 
	 * @return void    返回类型 
	 * @throws
	 */
	public void queryRepairOrderDelete() {
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean) act.getSession().get(
				Constant.LOGON_USER);
		String dealerId = logonUser.getDealerId();
		String dealerCode = logonUser.getDealerCode();
		try {
			RequestWrapper request = act.getRequest();
			Integer curPage = request.getParamValue("curPage") != null ? Integer
					.parseInt(request.getParamValue("curPage"))
					: 1; // 处理当前页
			String roNo = request.getParamValue("RO_NO");
			String vin = request.getParamValue("VIN");
			String repairType = request.getParamValue("REPAIR_TYPE");
			String roCreateDate = request.getParamValue("RO_CREATE_DATE");
			String deliveryDate = request.getParamValue("DELIVERY_DATE");
			String isForl = request.getParamValue("RO_FORE");
			String roStatus =request.getParamValue("RO_STATUS");
			String createDateStr = request.getParamValue("CREATE_DATE_STR");
			String createDateEnd = request.getParamValue("CREATE_DATE_END");
			Map<String,String> map = new HashMap();
			map.put("roNo", roNo);
			map.put("vin", vin);
			map.put("repairType", repairType);
			map.put("roCreateDate", roCreateDate);
			map.put("deliveryDate", deliveryDate);
			map.put("isForl", isForl);
			map.put("roStatus", roStatus);
			map.put("dealerId", dealerId);
			map.put("createDateStr", createDateStr);
			map.put("createDateEnd", createDateEnd);
			PageResult<TtAsRepairOrderExtPO> ps = dao.queryDeleteRepairOrderNew(map,Constant.PAGE_SIZE,curPage);
			act.setOutData("ps", ps);
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "工单删除");
			logger.error(logonUser, e1);
			act.setException(e1);
		}
	}

	/**
	 * 
	* @Title: queryRepairOrder 
	* @Description: TODO(查询预授权(OEM)) 
	* @param     设定文件 
	* @return void    返回类型 
	* @throws
	 */
	public void queryRepairOrder1() {
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean) act.getSession().get(
				Constant.LOGON_USER);
		String dealerId = logonUser.getDealerId();
		String dealerCode = logonUser.getDealerCode();
		try {
			RequestWrapper request = act.getRequest();
			Integer curPage = request.getParamValue("curPage") != null ? Integer
					.parseInt(request.getParamValue("curPage"))
					: 1; // 处理当前页
			String roNo = request.getParamValue("RO_NO");
			String vin = request.getParamValue("VIN");
			String repairType = request.getParamValue("REPAIR_TYPE");
			String roCreateDate = request.getParamValue("RO_CREATE_DATE");
			String deliveryDate = request.getParamValue("DELIVERY_DATE");
			String isForl = request.getParamValue("RO_FORE");
			String roStatus =request.getParamValue("RO_STATUS");
			String DId = request.getParamValue("dealerId");//经销商代码
			String orgCode = request.getParamValue("orgCode");
			String province = request.getParamValue("province");//省份CODE
			Map<String,String> map = new HashMap();
	
			map.put("roNo", roNo);
			map.put("vin", vin);
			map.put("repairType", repairType);
			map.put("roCreateDate", roCreateDate);
			map.put("deliveryDate", deliveryDate);
			map.put("isForl", isForl);
			map.put("roStatus", roStatus);
			map.put("dealerId", DId);
			map.put("orgCode", orgCode);
			map.put("province", province);
			PageResult<TtAsWrForeapprovalBean> ps = dao.queryRepairOrder1(logonUser.getUserId(),map,Constant.PAGE_SIZE,curPage);
			act.setOutData("ps", ps);
			//act.setForword(RO_URL);
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "索赔单维护");
			logger.error(logonUser, e1);
			act.setException(e1);
		}
	}

	/**
	 * 
	* @Title: queryRepairOrder 
	* @Description: TODO(经销商端查询预授权(OEM)) 
	* @param     设定文件 
	* @return void    返回类型 
	* @throws
	 */
	public void queryRepairOrderDealer() {
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean) act.getSession().get(
				Constant.LOGON_USER);
		String dealerId = logonUser.getDealerId();
		String dealerCode = logonUser.getDealerCode();
		try {
			RequestWrapper request = act.getRequest();
			Integer curPage = request.getParamValue("curPage") != null ? Integer
					.parseInt(request.getParamValue("curPage"))
					: 1; // 处理当前页
			String roNo = request.getParamValue("RO_NO");
			String vin = request.getParamValue("VIN");
			String repairType = request.getParamValue("REPAIR_TYPE");
			String roCreateDate = request.getParamValue("RO_CREATE_DATE");
			String deliveryDate = request.getParamValue("DELIVERY_DATE");
			String approveDate = request.getParamValue("approve_date");//审核时间
			String approveDate2 = request.getParamValue("approve_date2");
			String isForl = request.getParamValue("RO_FORE");
			String roStatus =request.getParamValue("RO_STATUS");
			//String DId = request.getParamValue("dealerId");//经销商代码
			String Did = logonUser.getDealerId();
			String orgCode = request.getParamValue("orgCode");
			Map<String,String> map = new HashMap();
			map.put("roNo", roNo);
			map.put("vin", vin);
			map.put("repairType", repairType);
			map.put("roCreateDate", roCreateDate);
			map.put("deliveryDate", deliveryDate);
			map.put("isForl", isForl);
			map.put("roStatus", roStatus);
			map.put("dealerId", Did);
			map.put("orgCode", orgCode);
			map.put("approveDate", approveDate);
			map.put("approveDate2", approveDate2);
			PageResult<TtAsWrForeapprovalBean> ps = dao.queryRepairOrderDealer(map,Constant.PAGE_SIZE,curPage);
			act.setOutData("ps", ps);
			//act.setForword(RO_URL);
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "索赔单维护");
			logger.error(logonUser, e1);
			act.setException(e1);
		}
	}
	

	public void queryRepairOrderOEM() {
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean) act.getSession().get(
				Constant.LOGON_USER);
		String dealerId = logonUser.getDealerId();
		String dealerCode = logonUser.getDealerCode();
		try {
			RequestWrapper request = act.getRequest();
			Integer curPage = request.getParamValue("curPage") != null ? Integer
					.parseInt(request.getParamValue("curPage"))
					: 1; // 处理当前页
			String roNo = request.getParamValue("RO_NO");
			String vin = request.getParamValue("VIN");
			String repairType = request.getParamValue("REPAIR_TYPE");
			String roCreateDate = request.getParamValue("RO_CREATE_DATE");
			String deliveryDate = request.getParamValue("DELIVERY_DATE");
			String approveDate = request.getParamValue("approve_date");//审核时间
			String approveDate2 = request.getParamValue("approve_date2");
			String auditName = request.getParamValue("auditName");//授权人
			String isForl = request.getParamValue("RO_FORE");
			String roStatus =request.getParamValue("RO_STATUS");
			String DId = request.getParamValue("dealerId");//经销商代码
			//String Did = logonUser.getDealerId();
			String orgCode = request.getParamValue("orgCode");
			Map<String,String> map = new HashMap();
			map.put("roNo", roNo);
			map.put("vin", vin);
			map.put("repairType", repairType);
			map.put("roCreateDate", roCreateDate);
			map.put("deliveryDate", deliveryDate);
			map.put("isForl", isForl);
			map.put("roStatus", roStatus);
			map.put("dealerId", DId);
			map.put("orgCode", orgCode);
			map.put("approveDate", approveDate);
			map.put("approveDate2", approveDate2);
			map.put("auditName", auditName);
			PageResult<TtAsWrForeapprovalBean> ps = dao.queryRepairOrderOEM(map,Constant.PAGE_SIZE,curPage);
			act.setOutData("ps", ps);
			//act.setForword(RO_URL);
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "索赔单维护");
			logger.error(logonUser, e1);
			act.setException(e1);
		}
	}
	
	/**
	 * 
	 * @Title: getOtherfeeStr
	 * @Description: TODO()
	 * @param
	 * @return 设定文件
	 * @return String 返回类型
	 * @throws
	 */
	public String getActivityStr() {
		ActionContext ctx = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean) ctx.getSession().get(
				Constant.LOGON_USER);
		List<TtAsActivityPO> seriesList = dao.queryActivityCombo();
		String retStr = "";
		retStr += "<option value=\',0,\'>-请选择-</option>";
		for (int i = 0; i < seriesList.size(); i++) {
			TtAsActivityPO bean = new TtAsActivityPO();
			bean = (TtAsActivityPO) seriesList.get(i);
			retStr += "<option value=\'" + bean.getActivityCode() + ","
					+ bean.getActivityFee() + "," + bean.getIsFixfee() + "\'>"
					+ bean.getActivityName() + "</option>";
		}
		return retStr;
	}
	
	/**
	 * 
	* @Title: approve 
	* @Description: TODO(对工单授权) 
	* @param     设定文件 
	* @return void    返回类型 
	* @throws
	 */
	public void approve() {
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean) act.getSession().get(
				Constant.LOGON_USER);
		try {
			RequestWrapper request = act.getRequest();
			String roNo = request.getParamValue("RO_NO"); 
			TtAsRepairOrderPO tarop = new TtAsRepairOrderPO();
			tarop.setRoNo(roNo);
			List<TtAsRepairOrderPO> ls  = dao.select(tarop);
			String vin ="";
			Integer freeTimes = 0;
			
			if (!Utility.testString(roNo)) {
				act.setOutData("success", false);
				act.setOutData("reason", true); //工单没有生成，不能授权
			}else {
				if (ls!=null) {
					if (ls.size()>0) {
						tarop = ls.get(0);
						vin = tarop.getVin();
						//freeTimes = tarop.getFreeTimes();
						TtAsRepairOrderPO tarop0 = new TtAsRepairOrderPO();
						tarop0.setRoNo(roNo);
						tarop0.setForlStatus(Constant.RO_FORE_01); //工单预授权通过
						dao.update(tarop, tarop0);
						
						/**预授权通过更新车辆信息表中的保养次数为工单中的保养次数****/
						TmVehiclePO tvps = new TmVehiclePO();
						tvps.setVin(vin);
						List<TmVehiclePO> lstvsp = dao.select(tvps);
						if(lstvsp!=null) {
							if (lstvsp.size()>0) {
								freeTimes = lstvsp.get(0).getFreeTimes();
							}
						}
						freeTimes=freeTimes+1; //更新车辆表中的保养次数为上次车辆表中的保养次数+1
						TmVehiclePO tvpsUp = new TmVehiclePO();
						if(Integer.valueOf(ls.get(0).getRepairTypeCode().toString())==11441004){
							tvpsUp.setFreeTimes(freeTimes);
						}
						dao.update(tvps,tvpsUp);
						act.setOutData("success", true);
						/*****************************************************/
						
					}else {
						act.setOutData("success", false);
						act.setOutData("reason", true); //工单没有生成，不能授权
						
					}
				}else {
					act.setOutData("success", false);
					act.setOutData("reason", true); //工单没有生成，不能授权
				}
				
			}
			
			//tarop.setIs
			
		}catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "质量信息");
			act.setOutData("success", false);
			act.setOutData("reason", false);
			logger.error(logonUser, e1);
			act.setException(e1);
		}
	}
	/**
	 * 
	* @Title: verDupRo 
	* @Description: TODO(校验工单表中是否已经存在要插入的工单) 
	* @param     设定文件 
	* @return void    返回类型 
	* @throws
	 */
	public void verDupRo() {
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean) act.getSession().get(
				Constant.LOGON_USER);
		try {
			RequestWrapper request = act.getRequest();
			String roNo = request.getParamValue("RO_NO"); 
			TtAsRepairOrderPO tarop = new TtAsRepairOrderPO();
			if (Utility.testString(roNo)) {
				tarop.setRoNo(roNo);
			}else {
				tarop.setRoNo("-1-1");
			}
			List<TtAsRepairOrderPO> ls = dao.select(tarop);
			if (ls!=null) {
				if (ls.size()>0) {
					act.setOutData("dup",true); //有重复
				}else {
					act.setOutData("dup",false);
				}
			}else {
				act.setOutData("dup",false);
			}
		}catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "质量信息");
			act.setOutData("success", false);
			logger.error(logonUser, e1);
			act.setException(e1);
		}
		
	}
	
	
	public void getFreeTimes(){
		ActionContext act = ActionContext.getContext();
		RequestWrapper request = act.getRequest();
		int allTimes=0;
		String vin = request.getParamValue("VIN"); //车辆VIN
		List<Map<String, Object>> freeTimes = dao.viewFreeTime1(vin);
		if(freeTimes.get(0).get("FREE_TIMES")==null||freeTimes.get(0).get("FREE_TIMES").equals("")){allTimes=0;}
		else{allTimes = Integer.valueOf(freeTimes.get(0).get("FREE_TIMES").toString());}
		act.setOutData("needTime",allTimes+1 ); //需要做的保养次数
	}
	
	/**
	 * 
	* @Title: getFree 
	* @Description: TODO(根据OEMCOMPANYID取得保养是否需要授权) 
	* @param     设定文件 
	* @return void    返回类型 
	* @throws
	 */
	public void getFree() {
		
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean) act.getSession().get(
				Constant.LOGON_USER);
		Long companyId = GetOemcompanyId.getOemCompanyId(logonUser); // 公司ID
		int freeTimesInApp = 0; //申请过的免费保养次数
		int freeTimesInAppy = 0; //预授权申请过的免费保养次数
		int freeTimesInAct = 0;
		int allTimes = 0;
		int day = 999999;
		int month = 999999; //当前时间和保修开始时间相差月份
		int monthIsQa = 0; //在规则表中的ont
		Double mileageDouble = 0.0;
		try {
			RequestWrapper request = act.getRequest();
			String vin = request.getParamValue("VIN"); //车辆VIN
			if(vin==null||vin.equals("")){
				System.out.println("----------未从页面获取VIN码-------------");
				throw new Exception("----------未从页面获取VIN码-------------");
			}
			String mileage = request.getParamValue("IN_MILEAGE");//进厂里程数
			String do_no = request.getParamValue("Do_No");
			String purchasedDate = request.getParamValue("PURCHASED_DATE"); //保修开始时间
			List<Map<String, Object>> mileage_vin = dao.getMileage(vin);//获取该车系统的最大行驶里程
			String db = request.getParamValue("DB");//用于区分是修改页面还是新增页面
			Date date = new Date();
			if (Utility.testString(purchasedDate)) {
				date = Utility.getDate(purchasedDate, 1);
			}else {
				mileageDouble =Utility.getDouble(mileage);
				TmVehiclePO tvp = new TmVehiclePO();
				tvp.setVin(vin);
				List<TmVehiclePO> lsv = dao.select(tvp);
				if (lsv!=null) {
					if (lsv.size()>0) {
						tvp = lsv.get(0);
					}
				}
				date = tvp.getPurchasedDate(); //保修改开始时间
			}
			Date now = new Date(); //今天
			if (date!=null) {
				String formatStyle ="yyyy-MM-dd";  
				SimpleDateFormat df = new SimpleDateFormat(formatStyle);  
				String d1 = df.format(date);
				String d2 = df.format(now);
				month  = Utility.compareDate(d1,d2,1); //取得今日和保养开始时间的插值
				day = Utility.compareDate(d1, d2, 0); //取得今日和保养开始时间的插值 天数
			}
			//以下freeTimesInApp，freeTimesInAppy在取出的值没有用到 将其注释掉
//			//工单中该车的保养次数(不需要预授权的)
//			TtAsRepairOrderPO tarop = new TtAsRepairOrderPO();
//			tarop.setVin(vin);
//			tarop.setApprovalYn(Constant.APPROVAL_YN_NO);
//			tarop.setRepairTypeCode(Constant.REPAIR_TYPE_04);
//			List<TtAsRepairOrderPO> lsa = dao.select(tarop);
//			if (lsa!=null) {
//				freeTimesInApp = lsa.size(); //取得免费保养申请次数
//			}
//			//需要预授权的
//			TtAsRepairOrderPO taropApp = new TtAsRepairOrderPO();
//			taropApp.setVin(vin);
//			taropApp.setApprovalYn(Constant.APPROVAL_YN_YES);
//			taropApp.setRepairTypeCode(Constant.REPAIR_TYPE_04);
//			taropApp.setForlStatus(Constant.RO_FORE_02);
//			List<TtAsRepairOrderPO> lsapp = dao.select(taropApp);
//			if (lsa!=null) {
//				freeTimesInAppy = lsapp.size(); //取得免费保养申请次数
//			}
			//服务活动中该车的保养次数
			//freeTimesInAct = dao.getActFree(vin);
			//allTimes = freeTimesInApp + freeTimesInAct+freeTimesInAppy;
			List<Map<String, Object>> freeTimes = dao.viewFreeTime1(vin);
			List<TtAsWrQamaintainPO> lsq=null;
			int in_milage=0;
			if(db!=null&&!db.equals("")){
				List<Map<String, Object>> DOList = dao.viewFreeTimeDoNo(do_no);
				allTimes = Integer.valueOf(DOList.get(0).get("FREE_TIMES").toString());
				lsq =  dao.getFree(allTimes,companyId,month,day,Double.valueOf(mileage));
				in_milage = Integer.valueOf(DOList.get(0).get("IN_MILEAGE").toString());
			}else{
				//判断保养次数是否为空
				if(freeTimes.get(0).get("FREE_TIMES")==null||freeTimes.get(0).get("FREE_TIMES").equals("")){
					allTimes=0;
				}
				else{allTimes = Integer.valueOf(freeTimes.get(0).get("FREE_TIMES").toString());}
				
				lsq =  dao.getFree(allTimes+1,companyId,month,day,Double.valueOf(mileage));
			}
			/** 最新修改需要从车辆表中取保养次数+1 */
//			TmVehiclePO tvsp = new TmVehiclePO();
//			tvsp.setVin(vin);
//			List<TmVehiclePO> lsvsp = dao.select(tvsp);
//			if (lsvsp!=null) {
//				if (lsvsp.size()>0) {
//					tvsp = lsvsp.get(0);
//					allTimes = tvsp.getFreeTimes()==null?0:tvsp.getFreeTimes();
//				}else {
//					
//				}
//			}else {
//				
//			}
			/****************************************/
			
			if (lsq!=null) {
				//存在记录，不需要授权
				if (lsq.size()>0) {
					act.setOutData("approve", false);
				}else {
					act.setOutData("approve", true);
				}
			}else {
				act.setOutData("approve", true);
			}
			Map mileageMap = new HashMap();
			mileageMap.put("MILEAGE", -1);
			act.setOutData("needTime",allTimes+1 ); //需要做的保养次数
			System.out.println(mileage_vin.size());
			act.setOutData("in_milage", in_milage);
			act.setOutData("mileage_vin", mileage_vin.size()==0?mileageMap:mileage_vin.get(0));//最大行驶里程
			//tarop.setIs
		}catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "质量信息");
			act.setOutData("success", false);
			logger.error(logonUser, e1);
			act.setException(e1);
		}
		
	}
	/**
	 * 
	* @Title: getGuaFlag 
	* @Description: TODO(判断配件是否在三包期内) 
	* @param     设定文件 
	* @return void    返回类型 
	* @throws
	 */
	public void getGuaFlag() {
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean) act.getSession().get(
				Constant.LOGON_USER);
		boolean flag = false; //不在三包范围
		int month= 99999;
		int interval = 0;
		
		try {
			RequestWrapper request = act.getRequest();
			String partCode = request.getParamValue("partCode");
			String vin = request.getParamValue("vin");
			String inMileage = request.getParamValue("inMileage");
			String purchasedDate = request.getParamValue("purchasedDate"); //保修开始时间
			WrRuleUtil util = new WrRuleUtil();
			if(purchasedDate==null||purchasedDate.equals("")){
				act.setOutData("flag",false);
			}
			else{
			WarrantyPartVO wp = util.wrRuleCompute(inMileage, purchasedDate, vin, partCode);
			act.setOutData("flag", wp.getIsInWarranty() == Constant.IF_TYPE_YES ?
					true : false);
			}
		}catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "质量信息");
			act.setOutData("success", false);
			logger.error(logonUser, e1);
			act.setException(e1);
		}
		
	}
	/*******
	 * 预授权申请单审核通过
	 */
	public void updateForStatus(){
		ActionContext act = ActionContext.getContext();
		RequestWrapper request = act.getRequest();
		AclUserBean logonUser = (AclUserBean) act.getSession().get(
				Constant.LOGON_USER);
		String id = request.getParamValue("ID");//获取公单ID
		String fid = request.getParamValue("fId");//获取预授权ID
		String opintion = request.getParamValue("opintion");//审核内容
		Integer payment = Integer.parseInt(request.getParamValue("payment"));//是否同意费用
		
		String vin = "-1";
		Integer freeTimes = 0;
		try {
		TtAsRepairOrderPO tarop = new TtAsRepairOrderPO();
		tarop.setId(Utility.getLong(id));
		List<TtAsRepairOrderPO> ls = dao.select(tarop);
		if (ls!=null) {
			if (ls.size()>0) {
				tarop = ls.get(0);
				vin = tarop.getVin();
				freeTimes = tarop.getFreeTimes();
			}
		}
		
		
		/**预授权通过更新车辆信息表中的保养次数为工单中的保养次数****/
		
		TmVehiclePO tvps = new TmVehiclePO();
		tvps.setVin(vin);
		List<TmVehiclePO> lstvsp = dao.select(tvps);
		//if(lstvsp!=null) {
			//if (lstvsp.size()>0) {
				//freeTimes = lstvsp.get(0).getFreeTimes()==null?0:lstvsp.get(0).getFreeTimes();
			//}
		//}
		//freeTimes=freeTimes+1; //更新车辆表中的保养次数为上次车辆表中的保养次数+1
		TmVehiclePO tvpsUp = new TmVehiclePO();
		if(Integer.valueOf(ls.get(0).getRepairTypeCode().toString())==11441004)
		{
			tvpsUp.setFreeTimes(freeTimes);
			//用于取购车时间
			TmVehiclePO tvp = new TmVehiclePO();
			tvp.setVin(vin);
			List<TmVehiclePO> lsv = dao.select(tvp);
			if(lsv!=null&&lsv.size()>0){
				if(lsv.get(0).getPurchasedDate()!=null){
					dao.update(tvps,tvpsUp);
				}
			}
			
		}
		act.setOutData("success", true);
		/*****************************************************/
		
		
		
		dao.updateTtAsWrForeapproval2(fid,opintion,payment);
		dao.updateTtAsRepairOrder(fid, payment,logonUser);
		dao.updateOrder(id);
		act.setForword(RO_URL);
		}catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "质量信息");
			act.setOutData("success", false);
			logger.error(logonUser, e1);
			act.setException(e1);
		}
	}
	
	/**
	 * Iverson add By 2010-12-09
	 * 预授权申请单批量审核通过
	 */
	public void updateForStatus2(){
		ActionContext act = ActionContext.getContext();
		RequestWrapper request = act.getRequest();
		AclUserBean logonUser = (AclUserBean) act.getSession().get(Constant.LOGON_USER);
		Integer payment = 0;
		String recesel [] = request.getParamValues("recesel");//获取一个集合预授权的ID
		
		//根据与授权ID得到工单号然后再根据工单号得到对应的工单ID
		TtAsWrForeapprovalPO po = new TtAsWrForeapprovalPO();
		TtAsWrForeapprovalPO poValue = new TtAsWrForeapprovalPO();
		TtAsRepairOrderPO orderPo = new TtAsRepairOrderPO();
		TtAsRepairOrderPO orderPoValue = new TtAsRepairOrderPO();
		for(String id:recesel){
			po.setId(Long.parseLong(id));
			poValue = (TtAsWrForeapprovalPO)dao.select(po).get(0);
			String roNo = poValue.getRoNo();
			orderPo.setRoNo(roNo);
			orderPoValue = (TtAsRepairOrderPO)dao.select(orderPo).get(0);
			String orderId = orderPoValue.getId().toString();
			String vin = "-1";
			Integer freeTimes = 0;
			try {
				TtAsRepairOrderPO tarop = new TtAsRepairOrderPO();
				tarop.setId(Utility.getLong(orderId));
				List<TtAsRepairOrderPO> ls = dao.select(tarop);
				if (ls!=null) {
					if (ls.size()>0) {
						tarop = ls.get(0);
						vin = tarop.getVin();
						freeTimes = tarop.getFreeTimes();
					}
				}
				/**预授权通过更新车辆信息表中的保养次数为工单中的保养次数****/
				TmVehiclePO tvps = new TmVehiclePO();
				tvps.setVin(vin);
				List<TmVehiclePO> lstvsp = dao.select(tvps);
				//if(lstvsp!=null) {
					//if (lstvsp.size()>0) {
						//freeTimes = lstvsp.get(0).getFreeTimes()==null?0:lstvsp.get(0).getFreeTimes();
					//}
				//}
				//freeTimes=freeTimes+1; //更新车辆表中的保养次数为上次车辆表中的保养次数+1
				TmVehiclePO tvpsUp = new TmVehiclePO();
				int aaa = Integer.valueOf(ls.get(0).getRepairTypeCode().toString());
				int bbb = Integer.valueOf(Constant.REPAIR_TYPE_04);
				
				if(Integer.parseInt(ls.get(0).getRepairTypeCode().toString())==Integer.parseInt(Constant.REPAIR_TYPE_04))
				{
					tvpsUp.setFreeTimes(freeTimes);
					//用于取购车时间
					TmVehiclePO tvp = new TmVehiclePO();
					tvp.setVin(vin);
					List<TmVehiclePO> lsv = dao.select(tvp);
					if(lsv!=null&&lsv.size()>0){
						if(lsv.get(0).getPurchasedDate()!=null){
							dao.update(tvps,tvpsUp);
						}
					}
					
				}
				/**预授权通过更新车辆信息表中的保养次数为工单中的保养次数****/
				dao.updateTtAsWrForeapproval2(id,"",payment);
				dao.updateTtAsRepairOrder(id, payment,logonUser);
				dao.updateOrder(orderId);
				act.setOutData("msg", "01");
			}catch (Exception e) {
				BizException e1 = new BizException(act, e,
						ErrorCodeConstant.QUERY_FAILURE_CODE, "质量信息");
				act.setOutData("success", false);
				logger.error(logonUser, e1);
				act.setException(e1);
			}
		}
	}
	
	/*******
	 * 预授权申请单审核退回
	 */
	public void backForStatus(){
		ActionContext act = ActionContext.getContext();
		RequestWrapper request = act.getRequest();
		String id = request.getParamValue("ID");//获取公单ID
		String fid = request.getParamValue("fId");//获取预授权ID
		String opintion = request.getParamValue("opintion");//审核内容
		dao.backTtAsWrForeapproval(fid,opintion);
		dao.backOrder(id);
		act.setForword(RO_URL);
	}//backForStatus
	
	public void  applicationRoNo(){
		ActionContext act = ActionContext.getContext();
		RequestWrapper request = act.getRequest();
		String roNo = request.getParamValue("roNo");
		List<Map<String, Object>> app = dao.getApplication(roNo);
		if(app.size()>0){
			act.setOutData("success", true);
			
		}
		else{
			
			act.setOutData("success", false);
		}
		
	}
	/**********
	 *  经销商dealerCode截取长度不足的补"X"
	 * @return
	 */
	public String sequenceRoNo(){
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean) act.getSession().get(
				Constant.LOGON_USER);
		String dealerCode = logonUser.getDealerCode();
		int len = dealerCode.length();
		String code="";
		String code1 = "";
		if(len<8){
			int i = 8-len;
			for(int k=0;k<i;k++){
				String zero ="0";
				code1+=zero;
			}
			code = dealerCode.substring(0,len)+code1;
		}
		if(len>=8){
		code = dealerCode.substring(0,8);
			
		}
		return code;
	}
	//判断是否脱保
	public Integer isFree(String vin,Double mileage,long companyId){
		int allTimes = 0;
		Date date = new Date();
		int day = 999999;
		int month = 999999; //当前时间和保修开始时间相差月份
		TmVehiclePO tvp = new TmVehiclePO();
		tvp.setVin(vin);
		List<TmVehiclePO> lsv = dao.select(tvp);
		if (lsv!=null) {
			if (lsv.size()>0) {
				tvp = lsv.get(0);
				date = tvp.getPurchasedDate(); //保修改开始时间
			}
		}
		Date now = new Date(); //今天
		if (date!=null) {
			String formatStyle ="yyyy-MM-dd";  
			SimpleDateFormat df = new SimpleDateFormat(formatStyle);  
			String d1 = df.format(date);
			String d2 = df.format(now);
			month  = Utility.compareDate(d1,d2,1); //取得今日和保养开始时间的插值
			day = Utility.compareDate(d1, d2, 0); //取得今日和保养开始时间的插值 天数
		}
		List<Map<String, Object>> freeTimes = dao.viewFreeTime1(vin);
		//判断保养次数是否为空
		if(freeTimes.get(0).get("FREE_TIMES")==null||freeTimes.get(0).get("FREE_TIMES").equals("")){
			allTimes=0;
		}
		else{allTimes = Integer.valueOf(freeTimes.get(0).get("FREE_TIMES").toString());}
		List<TtAsWrQamaintainPO> lsq=null;
		lsq =  dao.getFree(allTimes+1,companyId,month,day,Double.valueOf(mileage));
		if (lsq!=null) {
			//存在记录，不需要授权
			if (lsq.size()>0) {
			    return 1;
			}else {
			    return 0;
			}
		}else {
			return 0;
		}
	}
	//判断配件是否三包内的通用规则
	public Integer partIsGua(String purchasedDate,String inMileage,String vin,String partCode){
		int isGua=0;
			WrRuleUtil util = new WrRuleUtil();
			if(purchasedDate==null||purchasedDate.equals("")){
				isGua= 0;
			}
			else{
				try {
					WarrantyPartVO wp = util.wrRuleCompute(inMileage, purchasedDate, vin, partCode);
					 if(wp.getIsInWarranty() == Constant.IF_TYPE_YES){
						 
						 isGua= 1; 
					 } 
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		return isGua;
	}
	
	/**
	 * 删除工单信息
	 */
	public void deleteRepairOrder(){
		ActionContext act = ActionContext.getContext();
		RequestWrapper request = act.getRequest();
		AclUserBean logonUser = (AclUserBean) act.getSession().get(Constant.LOGON_USER);
		String id = request.getParamValue("ID");//工单ID
		//首先根据ID查询这条记录
		TtAsRepairOrderPO poById = new TtAsRepairOrderPO();
		poById.setId(Long.parseLong(id));
		List list = dao.selectRepairOrderById(poById);
		TtAsRepairOrderPO poBackValue = (TtAsRepairOrderPO)list.get(0);
		//其次在备份表里面新增记录
		TtAsRepairOrderBackupPO poBack = new TtAsRepairOrderBackupPO();
		poBack.setId(Long.parseLong(id));
		poBack.setDealerCode(poBackValue.getDealerCode());
		poBack.setRoNo(poBackValue.getRoNo());
		poBack.setSalesPartNo(poBackValue.getSalesPartNo());
		poBack.setBookingOrderNo(poBackValue.getBookingOrderNo());
		poBack.setEstimateNo(poBackValue.getEstimateNo());
		poBack.setSoNo(poBackValue.getSoNo());
		poBack.setRoType(poBackValue.getRoType());
		poBack.setRepairTypeCode(poBackValue.getRepairTypeCode());
		poBack.setOtherRepairType(poBackValue.getOtherRepairType());
		poBack.setVehicleTopDesc(poBackValue.getVehicleTopDesc());
		poBack.setSequenceNo(poBackValue.getSequenceNo());
		poBack.setPrimaryRoNo(poBackValue.getPrimaryRoNo());
		poBack.setInsurationNo(poBackValue.getInsurationNo());
		poBack.setInsurationCode(poBackValue.getInsurationCode());
		poBack.setIsCustomerInAsc(poBackValue.getIsCustomerInAsc());
		poBack.setIsSeasonCheck(poBackValue.getIsSeasonCheck());
		poBack.setOilRemain(poBackValue.getOilRemain());
		poBack.setIsWash(poBackValue.getIsWash());
		poBack.setIsTrace(poBackValue.getIsTrace());
		poBack.setTraceTime(poBackValue.getTraceTime());
		poBack.setNoTraceReason(poBackValue.getNoTraceReason());
		poBack.setNeedRoadTest(poBackValue.getNeedRoadTest());
		poBack.setRecommendEmpName(poBackValue.getRecommendEmpName());
		poBack.setRecommendCustomerName(poBackValue.getRecommendCustomerName());
		poBack.setServiceAdvisor(poBackValue.getServiceAdvisor());
		poBack.setServiceAdvisorAss(poBackValue.getServiceAdvisorAss());
		poBack.setRoStatus(poBackValue.getRoStatus());
		poBack.setRoCreateDate(poBackValue.getRoCreateDate());
		poBack.setEndTimeSupposed(poBackValue.getEndTimeSupposed());
		poBack.setChiefTechnician(poBackValue.getChiefTechnician());
		poBack.setOwnerNo(poBackValue.getOwnerNo());
		poBack.setOwnerName(poBackValue.getOwnerName());
		poBack.setOwnerProperty(poBackValue.getOwnerProperty());
		poBack.setLicense(poBackValue.getLicense());
		poBack.setVin(poBackValue.getVin());
		poBack.setEngineNo(poBackValue.getEngineNo());
		poBack.setBrand(poBackValue.getBrand());
		poBack.setSeries(poBackValue.getSeries());
		poBack.setModel(poBackValue.getModel());
		poBack.setInMileage(poBackValue.getInMileage());
		poBack.setOutMileage(poBackValue.getOutMileage());
		poBack.setIsChangeOdograph(poBackValue.getIsChangeOdograph());
		poBack.setChangeMileage(poBackValue.getChangeMileage());
		poBack.setTotalChangeMileage(poBackValue.getTotalChangeMileage());
		poBack.setTotalMileage(poBackValue.getTotalMileage());
		poBack.setDeliverer(poBackValue.getDeliverer());
		poBack.setDelivererGender(poBackValue.getDelivererGender());
		poBack.setDelivererPhone(poBackValue.getDelivererPhone());
		poBack.setDelivererMobile(poBackValue.getDelivererMobile());
		poBack.setFinishUser(poBackValue.getFinishUser());
		poBack.setCompleteTag(poBackValue.getCompleteTag());
		poBack.setWaitInfoTag(poBackValue.getWaitInfoTag());
		poBack.setWaitPartTag(poBackValue.getWaitPartTag());
		poBack.setCompleteTime(poBackValue.getCompleteTime());
		poBack.setForBalanceTime(poBackValue.getForBalanceTime());
		poBack.setDeliveryTag(poBackValue.getDeliveryTag());
		poBack.setDeliveryDate(poBackValue.getDeliveryDate());
		poBack.setDeliveryUser(poBackValue.getDeliveryUser());
		poBack.setLabourPrice(poBackValue.getLabourPrice());
		poBack.setLabourAmount(poBackValue.getLabourAmount());
		poBack.setRepairPartAmount(poBackValue.getRepairPartAmount());
		poBack.setSalesPartAmount(poBackValue.getSalesPartAmount());
		poBack.setAddItemAmount(poBackValue.getAddItemAmount());
		poBack.setOverItemAmount(poBackValue.getOverItemAmount());
		poBack.setRepairAmount(poBackValue.getRepairAmount());
		poBack.setEstimateAmount(poBackValue.getEstimateAmount());
		poBack.setBalanceAmount(poBackValue.getBalanceAmount());
		poBack.setReceiveAmount(poBackValue.getReceiveAmount());
		poBack.setSubobbAmount(poBackValue.getSubobbAmount());
		poBack.setDerateAmount(poBackValue.getDerateAmount());
		poBack.setFirstEstimateAmount(poBackValue.getFirstEstimateAmount());
		poBack.setTraceTag(poBackValue.getTraceTag());
		poBack.setRemark(poBackValue.getRemark());
		poBack.setRemark1(poBackValue.getRemark1());
		poBack.setRemark2(poBackValue.getRemark2());
		poBack.setTestDriver(poBackValue.getTestDriver());
		poBack.setPrintRoTime(poBackValue.getPrintRoTime());
		poBack.setRoChargeType(poBackValue.getRoChargeType());
		poBack.setPrintRpTime(poBackValue.getPrintRpTime());
		poBack.setEstimateBeginTime(poBackValue.getEstimateBeginTime());
		poBack.setIsActivity(poBackValue.getIsActivity());
		poBack.setIsCloseRo(poBackValue.getIsCloseRo());
		poBack.setIsMaintain(poBackValue.getIsMaintain());
		poBack.setCustomerDesc(poBackValue.getCustomerDesc());
		poBack.setRosplitStatus(poBackValue.getRosplitStatus());
		poBack.setMemberNo(poBackValue.getMemberNo());
		poBack.setInReason(poBackValue.getInReason());
		poBack.setModifyNum(poBackValue.getModifyNum());
		poBack.setQuoteEndAccurate(poBackValue.getQuoteEndAccurate());
		poBack.setCustomerPreCheck(poBackValue.getCustomerPreCheck());
		poBack.setCheckedEnd(poBackValue.getCheckedEnd());
		poBack.setExplainedBalanceAccounts(poBackValue.getExplainedBalanceAccounts());
		poBack.setNotEnterWorkshop(poBackValue.getNotEnterWorkshop());
		poBack.setIsTakePartOld(poBackValue.getIsTakePartOld());
		poBack.setLockUser(poBackValue.getLockUser());
		poBack.setDownTimestamp(poBackValue.getDownTimestamp());
		poBack.setIsvalid(poBackValue.getIsvalid());
		poBack.setCreateBy(poBackValue.getCreateBy());
		poBack.setCreateDate(poBackValue.getCreateDate());
		poBack.setUpdateBy(poBackValue.getUpdateBy());
		poBack.setUpdateDate(poBackValue.getUpdateDate());
		poBack.setDelivererAdress(poBackValue.getDelivererAdress());
		poBack.setGuaranteeDate(poBackValue.getGuaranteeDate());
		poBack.setForlStatus(poBackValue.getForlStatus());
		poBack.setCamCode(poBackValue.getCamCode());
		poBack.setAuditContent(poBackValue.getAuditContent());
		poBack.setFreeTimes(poBackValue.getFreeTimes());
		poBack.setApprovalYn(poBackValue.getApprovalYn());
		poBack.setIfStatus(poBackValue.getIfStatus());
		poBack.setDataType(poBackValue.getDataType());//////////////////
		poBack.setAccreditAmount(poBackValue.getAccreditAmount());
		poBack.setTroubleReason(poBackValue.getTroubleReason());
		poBack.setRepairMethod(poBackValue.getRepairMethod());
		poBack.setTroubleDescriptions(poBackValue.getTroubleDescriptions());
		poBack.setRemarks(poBackValue.getRemarks());
		//poBack.setIsDel(poBackValue.getIsDel());////////////////////////
		poBack.setOrderValuableType(poBackValue.getOrderValuableType().toString());
		poBack.setDealerId(poBackValue.getDealerId());
		
		//add by 2011-03-03
		poBack.setUpdateBy(logonUser.getUserId());
		poBack.setUpdateDate(new Date());
		//add by 2011-03-03 end
		
		dao.insertRepairOrder(poBack);
		//然后根据ID删除主表信息
		TtAsRepairOrderPO po = new TtAsRepairOrderPO();
		po.setId(Long.parseLong(id));
		//然后删除此工单生成过的预授权单子
		// add by zuoxj 存在预授权单子才执行删除操作
		if(dao.select(po).size()>0){
			TtAsRepairOrderPO poValue = (TtAsRepairOrderPO)dao.select(po).get(0);
			TtAsWrForeapprovalPO conPo = new TtAsWrForeapprovalPO();
			conPo.setRoNo(poValue.getRoNo());
			dao.delete(conPo);
			dao.delete(po);
		}
		roDeleteForward();//跳转至首页
	}
	
	
	/********add by liuxh 20101117 增加车厂工单查询功能*********/
	/**
	 * 
	* @Title: queryRepairOrder 
	* @Description: TODO(查询工单) 
	* @param     设定文件 
	* @return void    返回类型 
	* @throws
	* 工单信息查询
	 */
	public void repairOrderQuery() {
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean) act.getSession().get(
				Constant.LOGON_USER);
		String dealerId = logonUser.getDealerId();
		String dealerCode = logonUser.getDealerCode();
		try {
			String action=CommonUtils.checkNull(act.getRequest().getParamValue("action"));
			if("query".equals(action)){
				RequestWrapper request = act.getRequest();
				Integer curPage = request.getParamValue("curPage") != null ? Integer
						.parseInt(request.getParamValue("curPage"))
						: 1; // 处理当前页
				String roNo = request.getParamValue("RO_NO");
				String vin = request.getParamValue("VIN");
				String repairType = request.getParamValue("REPAIR_TYPE");
				String roCreateDate = request.getParamValue("RO_CREATE_DATE");
				String deliveryDate = request.getParamValue("DELIVERY_DATE");
				String isForl = request.getParamValue("RO_FORE");
				String roStatus =request.getParamValue("RO_STATUS");
				String createDateStr = request.getParamValue("CREATE_DATE_STR");
				String createDateEnd = request.getParamValue("CREATE_DATE_END");
				String dealerIdCon=CommonUtils.checkNull(request.getParamValue("dealerId"));
				Map<String,String> map = new HashMap();
				map.put("roNo", roNo);
				map.put("vin", vin);
				map.put("repairType", repairType);
				map.put("roCreateDate", roCreateDate);
				map.put("deliveryDate", deliveryDate);
				map.put("isForl", isForl);
				map.put("roStatus", roStatus);
				map.put("dealerId", dealerId);
				map.put("createDateStr", createDateStr);
				map.put("createDateEnd", createDateEnd);
				map.put("dealerIdCon", dealerIdCon);
				PageResult<TtAsRepairOrderExtPO> ps = dao.queryRepairOrderNewQuery(map,Constant.PAGE_SIZE,curPage);
				act.setOutData("ps", ps);
			}else{
				act.setForword("/jsp/repairorder/roMaintainQuery.jsp");
			}
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "工单查询");
			logger.error(logonUser, e1);
			act.setException(e1);
		}
	}
	/********add by liuxh 20101117 增加车厂工单查询功能*********/
	
	
	/********add by liuxh 20101119 车辆车主信息查询功能*********/
	/**
	 * 
	* @Title: queryRepairOrder 
	* @Description: TODO(查询工单) 
	* @param     设定文件 
	* @return void    返回类型 
	* @throws
	* 工单信息查询
	 */
	public void vehicleCusInfoQuery() {
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean) act.getSession().get(
				Constant.LOGON_USER);
		String dealerId = logonUser.getDealerId();
		String dealerCode = logonUser.getDealerCode();
		String yieldlyUser = CommonUtils.findYieldlyByPoseId(logonUser.getPoseId());
		try {
			String action=CommonUtils.checkNull(act.getRequest().getParamValue("action"));
			if("query".equals(action)){
				RequestWrapper request = act.getRequest();
				Integer curPage = request.getParamValue("curPage") != null ? Integer
						.parseInt(request.getParamValue("curPage"))
						: 1; // 处理当前页
				String vin=CommonUtils.checkNull(request.getParamValue("VIN"));
				String carStatus=CommonUtils.checkNull(request.getParamValue("CAR_STATUS"));
				String yieldly=CommonUtils.checkNull(request.getParamValue("yieldly"));
				String carNo=CommonUtils.checkNull(request.getParamValue("CAR_NO"));
				String cusName=CommonUtils.checkNull(request.getParamValue("CUS_NAME"));
						
				Map<String,String> map = new HashMap();
				map.put("vin", vin);
				map.put("carStatus", carStatus);
				map.put("yieldly", yieldly);
				map.put("carNo", carNo);
				map.put("cusName", cusName);
				map.put("yieldlyUser", yieldlyUser);
			
				PageResult<Map> ps = dao.vehicleCusInfoQuery(map,Constant.PAGE_SIZE,curPage);
				act.setOutData("ps", ps);
			}else{
				act.setOutData("yieldly", yieldlyUser);
				act.setForword("/jsp/repairorder/vehicleCusInfoQuery.jsp");
			}
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "工单查询");
			logger.error(logonUser, e1);
			act.setException(e1);
		}
	}
	public void vehicleCusInfoDetail(){
		ActionContext act = ActionContext.getContext();
		String vehicleId=CommonUtils.checkNull(act.getRequest().getParamValue("vehicleId"));
		Map map=(Map)dao.getVehcleCusDetial(Long.valueOf(vehicleId)).get(0);
		act.setOutData("detailMap", map);
		act.setForword("/jsp/repairorder/vehicleCustomerDetail.jsp");
	}
	/********add by liuxh 20101119 车辆车主信息查询功能*********/
	
	/**
	 * Iverson add By 2010-12-08
	 * @Title: queryRepairOrder 
	 * @Description: TODO(车辆信息历史查询) 
	 * @param     设定文件 
	 * @return void    返回类型 
	 * @throws
	 */
	public void vehicleHistoryInfoQuery() {
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		try {
			act.setForword("/jsp/repairorder/vehicleHistoryInfoQuery.jsp");
		}catch(Exception e) {//异常方法
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"VIN码查车辆信息");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	
	/**
	 * yx add By 2010-12-17
	 * @Title: vehiclePinReplyQuery 
	 * @Description: TODO(PIN查询回复) 
	 * @param     设定文件 
	 * @return void    返回类型 
	 * @throws
	 */
	public void vehiclePinReplyQuery() {
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		RequestWrapper request = act.getRequest();
		try {
			String COMMAND = CommonUtils.checkNull(request.getParamValue("COMMAND"));
			if(!"".equals(COMMAND)){
				String companyName = CommonUtils.checkNull(request.getParamValue("companyName"));
				String vin = CommonUtils.checkNull(request.getParamValue("vin"));
				String pinCreateDate = CommonUtils.checkNull(request.getParamValue("PIN_CREATE_DATE"));
				String pinEndDate = CommonUtils.checkNull(request.getParamValue("PIN_END_DATE"));
				String status = CommonUtils.checkNull(request.getParamValue("status"));
				String pinCode = CommonUtils.checkNull(request.getParamValue("pinCode"));
				String dealerCode = CommonUtils.checkNull(request.getParamValue("dealerCode"));
				Integer curPage = request.getParamValue("curPage") != null ? Integer
						.parseInt(request.getParamValue("curPage"))
						: 1; // 处理当前页
				PageResult<Map<String, Object>> ps = dao.getVehclePinSubmitRequest(companyName,vin,
						pinCreateDate,pinEndDate,status,pinCode,dealerCode,curPage);
				act.setOutData("ps", ps);
			}else{
				act.setForword(VEHICLE_PIN_REPLY_QUERY);
			}
		}catch(Exception e) {//异常方法
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"VIN码查车辆信息");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	
	/**
	 * yx add By 2010-12-17
	 * @Title: vehiclePinReplyQueryDetail 
	 * @Description: TODO(PIN回复查询明细) 
	 * @param     设定文件 
	 * @return void    返回类型 
	 * @throws
	 */
	public void vehiclePinReplyQueryDetail() {
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		RequestWrapper request = act.getRequest();
		try {
			String COMMAND = CommonUtils.checkNull(request.getParamValue("COMMAND"));
			String pinId = CommonUtils.checkNull(request.getParamValue("pinId"));
			if(!"".equals(COMMAND)){
				String pinNo = CommonUtils.checkNull(request.getParamValue("pinNo"));
				String replyRemark = CommonUtils.checkNull(request.getParamValue("replyRemark"));
				TmVehiclePinRequestPO pinReq = new TmVehiclePinRequestPO();
				pinReq.setPinId(Long.valueOf(pinId));
				TmVehiclePinRequestPO pinReqValue = new TmVehiclePinRequestPO();
				pinReqValue.setPin(pinNo);
				//修改
				pinReqValue.setBackRemark(replyRemark);
				//回复
				pinReqValue.setStatus(Constant.VEHICLE_PIN_02);
				
				pinReqValue.setUpdateBy(logonUser.getUserId());
				pinReqValue.setUpdateDate(new Date());
				int msg = dao.update(pinReq, pinReqValue);
				act.setOutData("msg", msg);
			}else{
				
				Map<String, Object> ps = dao.getVehclePinDetail(pinId);
				act.setOutData("ps", ps);
				act.setForword(VEHICLE_PIN_REPLY_DETAIL);
			}
		}catch(Exception e) {//异常方法
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"VIN码查车辆信息");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	
	/********Iverson add by 2010-12-08 判断vin码在库中是否存在*********/
	public void vehicleHistoryInfoQuery1() {
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		RequestWrapper request = act.getRequest();
		try {
			String vin = request.getParamValue("vin");
			int count = dao.getCount(vin);
			if(count>0){
				act.setOutData("ok", "ok");
			}
		}catch(Exception e) {//异常方法
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"VIN码查车辆信息");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	/********Iverson add by 2010-12-08 判断vin码在库中是否存在*********/
	
	/********yx add by 2010-12-18 判断结算时配件是否属配件大类*********/
	//弹出窗方式
	public void checkRepairOrderPart() {
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		RequestWrapper request = act.getRequest();
		try {
			//判断登陆系统
			List<Map<String,Object>> ListCode =   dao.queryTcCode();
		    Integer code = Integer.valueOf(ListCode.get(0).get("CODE_ID").toString());
		    if(code==Constant.chana_wc){
			
				//检查工单配件是不是配件大类
		    	String roId = CommonUtils.checkNull(request.getParamValue("roId"));
				List<Map<String,String>> partCode = dao.getRepairOrderPartCheck(roId); 
				String partStr = "";
				for(int j=0;j<partCode.size();j++){
					if(partCode.get(j).get("PART_TYPE_ID")==null){
						if("".equals(partStr)){
							partStr = partCode.get(j).get("PART_NO").toString();
						}else{
							partStr = partStr +","+ partCode.get(j).get("PART_NO").toString();
						}
					}
				}
				act.setOutData("partStr",partStr);
				
			}
		}catch(Exception e) {//异常方法
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"验证配件大类失败！");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	/********yx add by 2010-12-18 判断结算时配件是否属配件大类*********/
}
